本文說明如何使用 Cloud Data Loss Prevention API 偵測圖片中的私密文字和物件。Sensitive Data Protection 會傳回偵測到的任何私密資料位置。
以圖片輸入時,Sensitive Data Protection 會偵測圖片中的機密資料。檢查作業的輸出包含偵測到的 infoTypes、資料相符的可能性,以及像素座標和長度值,指出機密資料保護功能在哪些區域找到機密資料。圖片左下角的座標為 (0,0)
。
檢查圖片是否含有所有預設 infoType
如要檢查圖片是否含有機密資料,請將 Base64 編碼圖片提交至 content.inspect
方法。如果未指定要搜尋的特定資訊類型 (infoTypes),機密資料防護會搜尋最常見的 infoType。
如要檢查圖片是否含有所有預設 infoType,請按照下列步驟操作:
- 將圖片編碼為 Base64。
- 向 DLP API 的
content.inspect
方法提交要求。 要求只需要 Base64 編碼的圖片。
舉例來說,請參考這張文件圖片。

C#
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
REST
如要檢查這張圖片是否含有預設 infoType,請將下列 JSON 傳送至 content.inspect
方法:
{ "item": { "byteItem": { "data": "BASE64_ENCODED_IMAGE", "type": "IMAGE_PNG" } } }
輸出結果會與下列內容相似:
{ "result": { "findings": [ { "infoType": { "name": "PERSON_NAME", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 383, "left": 419, "width": 82, "height": 38 }, { "top": 383, "left": 494, "width": 91, "height": 37 } ] } } ] }, "createTime": "2025-05-22T20:27:03.730Z", "findingId": "2025-05-22T20:27:03.731510Z4997664074931396457" }, { "infoType": { "name": "EMAIL_ADDRESS", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "VERY_LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 445, "left": 390, "width": 357, "height": 48 } ] } } ] }, "createTime": "2025-05-22T20:27:03.728Z", "findingId": "2025-05-22T20:27:03.731538Z284444825812417100" }, { "infoType": { "name": "PHONE_NUMBER", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "VERY_LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 515, "left": 404, "width": 223, "height": 34 } ] } } ] }, "createTime": "2025-05-22T20:27:03.729Z", "findingId": "2025-05-22T20:27:03.731544Z7910624062018243126" }, { "infoType": { "name": "PERSON_NAME", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "UNLIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 798, "left": 473, "width": 81, "height": 45 } ] } } ] }, "createTime": "2025-05-22T20:27:03.730Z", "findingId": "2025-05-22T20:27:03.731551Z2345136870450870227" }, { "infoType": { "name": "PERSON_NAME", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "UNLIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 837, "left": 1166, "width": 46, "height": 45 } ] } } ] }, "createTime": "2025-05-22T20:27:03.730Z", "findingId": "2025-05-22T20:27:03.731557Z6725780456697828166" }, { "infoType": { "name": "PERSON_NAME", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "UNLIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 915, "left": 453, "width": 141, "height": 43 } ] } } ] }, "createTime": "2025-05-22T20:27:03.730Z", "findingId": "2025-05-22T20:27:03.731562Z7328853308213386463" }, { "infoType": { "name": "PERSON_NAME", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "UNLIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 915, "left": 1180, "width": 105, "height": 43 } ] } } ] }, "createTime": "2025-05-22T20:27:03.730Z", "findingId": "2025-05-22T20:27:03.731569Z5618332947461439057" } ] } }
在本範例中,Sensitive Data Protection 找到下列 infoType,但每項的比對信賴度各不相同:
PERSON_NAME
EMAIL_ADDRESS
PHONE_NUMBER
如要進一步瞭解如何將 DLP API 與 JSON 搭配使用,請參閱 JSON 快速入門導覽課程。
請注意,Sensitive Data Protection 通常會使用多個方塊,指出圖片中單一例項的私密資料位置。
檢查圖片是否含有特定 infoType
如要檢查圖片是否只含有特定類型的機密資料,請指定對應的內建 infoType。
如要檢查圖片是否含有特定資訊類型,請按照下列步驟操作:
- 將圖片編碼為 Base64。
- 向 DLP API 的
content.inspect
方法提交要求。要求必須包含下列資訊:- Base64 編碼的圖片。
- 一或多個 infoType 偵測工具。
C#
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
REST
請參考上一節的原始圖片。如要只檢查電子郵件地址和電話號碼,請將下列 JSON 傳送至 content.inspect
方法。
{ "item": { "byteItem": { "data": "BASE64_ENCODED_IMAGE", "type": "IMAGE_PNG" } }, "inspectConfig": { "infoTypes": [ { "name": "PHONE_NUMBER" }, { "name": "EMAIL_ADDRESS" } ] } }
輸出結果會與下列內容相似:
{ "result": { "findings": [ { "infoType": { "name": "EMAIL_ADDRESS", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "VERY_LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 445, "left": 390, "width": 357, "height": 48 } ] } } ] }, "createTime": "2025-05-22T20:59:48.653Z", "findingId": "2025-05-22T20:59:48.654873Z3907900286477341146" }, { "infoType": { "name": "PHONE_NUMBER", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "VERY_LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 515, "left": 404, "width": 223, "height": 34 } ] } } ] }, "createTime": "2025-05-22T20:59:48.653Z", "findingId": "2025-05-22T20:59:48.654914Z7486984971818202511" } ] } }
如要進一步瞭解如何將 DLP API 與 JSON 搭配使用,請參閱 JSON 快速入門導覽課程。
檢查圖片是否含有敏感物件
如要檢查圖片是否含有機密物件,請在要求中指定內建物件 infoType 偵測器。
如要檢查圖片是否含有特定物件資訊類型,請按照下列步驟操作:
- 將圖片編碼為 Base64。
- 向 DLP API 的
content.inspect
方法提交要求。要求必須包含下列資訊:- Base64 編碼的圖片。
- 一或多個物件 infoType 偵測器。
舉例來說,請參考下圖。

如要檢查這張圖片是否含有特定物件 infoType,請將下列 JSON 傳送至 content.inspect
方法:
{ "item": { "byteItem": { "data": "BASE64_ENCODED_IMAGE", "type": "IMAGE_PNG" } }, "inspectConfig": { "infoTypes": [ { "name": "OBJECT_TYPE/BARCODE" }, { "name": "OBJECT_TYPE/LICENSE_PLATE" }, { "name": "OBJECT_TYPE/WHITEBOARD" } ] } }
輸出結果會與下列內容相似:
{ "result": { "findings": [ { "infoType": { "name": "OBJECT_TYPE/WHITEBOARD", "sensitivityScore": { "score": "SENSITIVITY_LOW" } }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "left": 427, "width": 561, "height": 678 } ] } } ] }, "createTime": "2025-05-22T22:25:09.564718Z", "findingId": "2025-05-22T22:25:09.564721Z3400818180961962648" }, { "infoType": { "name": "OBJECT_TYPE/LICENSE_PLATE", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 554, "left": 137, "width": 187, "height": 70 } ] } } ] }, "createTime": "2025-05-22T22:25:09.564752Z", "findingId": "2025-05-22T22:25:09.564753Z2359274424382836782" }, { "infoType": { "name": "OBJECT_TYPE/BARCODE", "sensitivityScore": { "score": "SENSITIVITY_LOW" } }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 569, "left": 666, "width": 306, "height": 274 } ] } } ] }, "createTime": "2025-05-22T22:25:09.564762Z", "findingId": "2025-05-22T22:25:09.564762Z1655085669963455621" } ] } }
如要進一步瞭解如何將 DLP API 與 JSON 搭配使用,請參閱 JSON 快速入門導覽課程。
程式碼範例
以下是幾種不同程式語言的程式碼範例,示範如何使用機密資料保護服務檢查圖片中的機密資料。
C#
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章。
如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
立即體驗
您可以在 content.inspect
的參考資料頁面中,透過 API Explorer 試用這些範例,或使用自己的圖片進行實驗:
後續步驟
- 進一步瞭解圖片檢查和遮蓋。
- 瞭解如何遮蓋圖片中的機密資料。