本文档介绍了如何使用 Cloud Data Loss Prevention API 检测图片中的敏感文本和对象。Sensitive Data Protection 会返回其检测到的所有敏感数据的位置。
给定图片作为输入后,Sensitive Data Protection 会检测图片中的敏感数据。检查操作的输出包括检测到的 infoTypes、匹配的可能性以及像素坐标和长度值,这些值指示 Sensitive Data Protection 找到敏感数据的区域。图片左下角的坐标为 (0,0)。
检查图片中是否存在所有默认 infoType
如需检查图片中是否存在敏感数据,请向 content.inspect 方法提交 base64 编码图片。如果您未指定要搜索的特定信息类型 (infoTypes),Sensitive Data Protection 会搜索最常见的 infoType。
如需检查图片中的所有默认 infoType,请按以下步骤操作:
- 对图片进行 base64 编码。
- 向 DLP API 的
content.inspect方法提交请求。 该请求只需要 base64 编码的图片。
例如,假设有以下文档图片。
C#
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Go
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 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,但每个 infoType 的匹配可信度各不相同:
PERSON_NAMEEMAIL_ADDRESSPHONE_NUMBER
如需详细了解如何将 DLP API 与 JSON 搭配使用,请参阅 JSON 快速入门。
请注意,Sensitive Data Protection 通常会使用多个框来指示敏感数据在图片中的单个实例所在的位置。
检查图片中是否存在特定 infoType
如需仅检查图片中的某些敏感数据类型,请指定其对应的内置 infoType。
如需检查图片中是否存在特定 infoType,请按以下步骤操作:
- 对图片进行 base64 编码。
- 向 DLP API 的
content.inspect方法提交请求。请求必须包含以下内容:- Base64 编码的图片。
- 一个或多个 infoType 检测器。
C#
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Go
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 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 检测器。
如需检查图片中是否存在特定对象 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 快速入门。
检查多页 TIFF 图片
Sensitive Data Protection 可以检查 TIFF 图片,包括最多 50 页的多页 TIFF 图片。它会检查图片的每一页,并在单个响应中返回所有页面的发现结果。
如需检查 TIFF 图片,请按以下步骤操作:
- 将 TIFF 图片编码为 base64。
- 向 DLP API 的
content.inspect方法提交请求。在请求中,将字节项的type设置为IMAGE_TIFF。
例如,如需检查 TIFF 图片中是否存在默认 infoType,请将以下 JSON 请求正文发送到 content.inspect 方法:
{ "item": { "byteItem": { "data": "BASE64_ENCODED_IMAGE", "type": "IMAGE_TIFF" } } }
在响应中,每个发现结果的 imageLocation 包含一个 pageNumber 字段,用于标识包含发现结果的页面。页码从 0 开始。输出类似于以下内容:
{ "result": { "findings": [ { "infoType": { "name": "EMAIL_ADDRESS", "sensitivityScore": { "score": "SENSITIVITY_MODERATE" } }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 213, "left": 128, "width": 345, "height": 40 } ], "pageNumber": 1 } } ] }, "createTime": "2026-10-23T10:15:03.730Z", "findingId": "2026-10-23T10:15:03.731510Z4997664074931396457" } ] } }
在此示例中,Sensitive Data Protection 在图片的第二页上找到了 EMAIL_ADDRESS。
检查 TIFF 图片时,请考虑以下几点:
- TIFF 图片最多可包含 50 页。如果 TIFF 图片包含更多页面,请求会失败。如需了解详情,请参阅 TIFF 扫描限制。
- TIFF 图片不支持基于图片的排除规则和调整规则(
ExcludeByImageFindings和AdjustByImageFindings)。如果您的检查配置包含这些规则,则请求会失败。 - 您可以检查 TIFF 图片,但无法对其进行隐去处理。
- 与其他图片类型一样,您只能在支持图片扫描的位置检查 TIFF 图片。
代码示例
以下是多种语言的示例代码,演示了如何使用 Sensitive Data Protection 检查图片中的敏感数据。
C#
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Go
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库。
如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证。
试试看
您可以在 content.inspect 的 API Explorer 的参考页面中自行尝试每个示例,或者尝试您自己的图片:
后续步骤
- 详细了解图片检查和遮盖。
- 了解如何遮盖图片中的敏感数据。