敏感数据保护可以检测图片中的敏感数据并对其进行分类。 敏感数据保护使用 infoType 检测器和光学字符识别 (OCR) 功能检查 base64 编码图片中的文本,检测文本中的敏感数据,然后返回检测到的任何敏感数据的位置。
若将图片作为输入,敏感数据保护会检测图片中的敏感数据。检查操作的输出包括找到的 infoTypes、匹配的可能性,以及指示敏感数据保护在其中发现敏感数据的区域的像素坐标和长度值。图片左下角的坐标为 (0,0)
。
检查所有默认 infoType 的图片
要检查图片中的敏感数据,请向 DLP API 的 content.inspect
方法提交使用 base64 编码的图片。除非您指定要搜索的特定信息类型 (infoTypes),否则敏感数据保护会搜索最常见的 infoType。
要检查图片的默认 infoType,请执行以下操作:
- 对图片进行 base64 编码。
- 向 DLP API 的
content.inspect
方法提交请求。如果您要检查默认 infoType,则请求只需包含 base64 编码的图片。
例如,请参考下面的图片:此图片是通过扫描纸质文档生成的典型图片文件示例。
要检查此图片以获取默认 infoType,请将以下请求发送到 DLP API 的 content.inspect
方法:
C#
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Go
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
REST
{ "item": { "byteItem": { "data": "[BASE64-ENCODED-IMAGE]", "type": "IMAGE_JPEG" } } }
敏感数据保护会返回以下内容:
{ "result": { "findings": [ { "infoType": { "name": "PHONE_NUMBER" }, "likelihood": "UNLIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 98, "left": 986, "width": 102, "height": 117 }, { "top": 98, "left": 1092, "width": 29, "height": 114 }, { "top": 95, "left": 1111, "width": 82, "height": 115 }, { "top": 95, "left": 1197, "width": 29, "height": 114 }, { "top": 90, "left": 1203, "width": 185, "height": 118 } ] } } ] }, "createTime": "2019-11-01T22:07:05.870Z" }, { "infoType": { "name": "US_SOCIAL_SECURITY_NUMBER" }, "likelihood": "VERY_LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 98, "left": 986, "width": 102, "height": 117 }, { "top": 98, "left": 1092, "width": 29, "height": 114 }, { "top": 95, "left": 1111, "width": 82, "height": 115 }, { "top": 95, "left": 1197, "width": 29, "height": 114 }, { "top": 90, "left": 1203, "width": 185, "height": 118 } ] } } ] }, "createTime": "2019-11-01T22:07:05.871Z" }, { "infoType": { "name": "EMAIL_ADDRESS" }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 340, "left": 334, "width": 57, "height": 58 }, { "top": 340, "left": 384, "width": 12, "height": 58 }, { "top": 340, "left": 387, "width": 79, "height": 59 }, { "top": 341, "left": 467, "width": 12, "height": 58 }, { "top": 340, "left": 476, "width": 119, "height": 61 }, { "top": 341, "left": 589, "width": 12, "height": 58 }, { "top": 342, "left": 592, "width": 45, "height": 58 } ] } } ] }, "createTime": "2019-11-01T22:07:05.869Z" }, { "infoType": { "name": "PHONE_NUMBER" }, "likelihood": "POSSIBLE", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 394, "left": 335, "width": 50, "height": 77 }, { "top": 394, "left": 380, "width": 17, "height": 77 }, { "top": 394, "left": 387, "width": 51, "height": 77 }, { "top": 394, "left": 433, "width": 17, "height": 77 }, { "top": 394, "left": 436, "width": 77, "height": 77 } ] } } ] }, "createTime": "2019-11-01T22:07:05.870Z" }, { "infoType": { "name": "DATE" }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 572, "left": 1129, "width": 71, "height": 38 } ] } } ] }, "createTime": "2019-11-01T22:07:05.921Z" } ] } }
敏感数据保护发现了以下 infoType,但每个 infoType 的匹配置信度各不相同:
- 电话号码(不太可能)
- 美国社会保障号(很有可能)
- 电子邮件地址(可能)
- 电话号码(可能)
- 日期(可能)
如果要在图片上绘制每个边界框,则它可能如下所示。请注意,敏感数据保护通常使用多个框来指示图片中单个敏感数据实例的位置。
请注意,敏感数据保护除了检测手写社会保障号、电子邮件地址和手机号码外,还检测到了年份。假设这不是最佳行为,下一个示例演示了如何仅检查特定 infoType。
检查特定 infoType 的图片
如果要仅检查图片的某些敏感数据类型,请指定其对应的内置 infoType。
要检查图片的特定 infoType,请执行以下操作:
- 对图片进行 base64 编码。
- 向 DLP API 的
content.inspect
方法提交请求。该请求必须包含:- Base64 编码的图片。
- 一个或多个 infoType 检测器。
请参考上一部分中的原始图片。要仅检查美国社会保障号、电子邮件地址和电话号码,请将以下 JSON 发送到 DLP API 的 content.inspect
方法:
C#
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Go
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
REST
{ "item": { "byteItem": { "data": "[BASE64-ENCODED-IMAGE]", "type": "IMAGE_JPEG" } }, "inspectConfig": { "infoTypes": [ { "name": "US_SOCIAL_SECURITY_NUMBER" }, { "name": "PHONE_NUMBER" }, { "name": "EMAIL_ADDRESS" } ] } }
敏感数据保护会返回以下内容:
{ "result": { "findings": [ { "infoType": { "name": "US_SOCIAL_SECURITY_NUMBER" }, "likelihood": "VERY_LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 98, "left": 986, "width": 102, "height": 117 }, { "top": 98, "left": 1092, "width": 29, "height": 114 }, { "top": 95, "left": 1111, "width": 82, "height": 115 }, { "top": 95, "left": 1197, "width": 29, "height": 114 }, { "top": 90, "left": 1203, "width": 185, "height": 118 } ] } } ] }, "createTime": "2019-11-01T22:58:56.985Z" }, { "infoType": { "name": "EMAIL_ADDRESS" }, "likelihood": "LIKELY", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 340, "left": 334, "width": 57, "height": 58 }, { "top": 340, "left": 384, "width": 12, "height": 58 }, { "top": 340, "left": 387, "width": 79, "height": 59 }, { "top": 341, "left": 467, "width": 12, "height": 58 }, { "top": 340, "left": 476, "width": 119, "height": 61 }, { "top": 341, "left": 589, "width": 12, "height": 58 }, { "top": 342, "left": 592, "width": 45, "height": 58 } ] } } ] }, "createTime": "2019-11-01T22:58:56.984Z" }, { "infoType": { "name": "PHONE_NUMBER" }, "likelihood": "POSSIBLE", "location": { "contentLocations": [ { "imageLocation": { "boundingBoxes": [ { "top": 394, "left": 335, "width": 50, "height": 77 }, { "top": 394, "left": 380, "width": 17, "height": 77 }, { "top": 394, "left": 387, "width": 51, "height": 77 }, { "top": 394, "left": 433, "width": 17, "height": 77 }, { "top": 394, "left": 436, "width": 77, "height": 77 } ] } } ] }, "createTime": "2019-11-01T22:58:56.985Z" } ] } }
从输出结果中可以看出,敏感数据保护找到了美国社会保障号、电子邮件地址和电话号码。
要详细了解如何将 DLP API 与 JSON 结合使用,请参阅 JSON 快速入门。
代码示例
下面是多种语言的示例代码,其中演示了如何使用敏感数据保护来检查图片是否存在敏感数据。
C#
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Go
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
PHP
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需了解如何安装和使用用于敏感数据保护的客户端库,请参阅敏感数据保护客户端库。
如需向敏感数据保护服务进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
试试看
您可以在 content.inspect
的 API Explorer 的参考页面中自行尝试每个示例,或者尝试您自己的图片:
后续步骤
- 详细了解图片检查和遮盖。
- 了解如何隐去图片中的敏感数据。