Sensitive Data Protection can detect and classify sensitive data within an image. Using infoType detectors and optical character recognition (OCR), Sensitive Data Protection inspects a base64-encoded image for text, detects sensitive data within the text, and then returns the locations of any sensitive data that it has detected.
Given an image as input, Sensitive Data Protection detects sensitive data
in the image. The output of an inspection operation includes the found
infoTypes, the
likelihood of the match, and pixel
coordinate and length values that indicate the areas within which
Sensitive Data Protection found the sensitive data. The coordinates at the bottom
left corner of an image are (0,0)
.
Inspecting an image for all default infoTypes
To inspect an image for sensitive data, you submit a base64-encoded image to the
DLP API's
content.inspect
method. Unless you specify specific information types
(infoTypes) to search for, Sensitive Data Protection
searches for the most common infoTypes.
To inspect an image for default infoTypes:
- Encode the image as base64.
- Submit a request to the DLP API's
content.inspect
method. The request need only contain the base64-encoded image if you want to inspect for default infoTypes.
For example, consider the following image. This image is an example of a typical image file generated from a scan of a paper document.
To inspect this image for default infoTypes, send the following request to
the DLP API's
content.inspect
method:
C#
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST
{ "item": { "byteItem": { "data": "[BASE64-ENCODED-IMAGE]", "type": "IMAGE_JPEG" } } }
Sensitive Data Protection returns the following:
{ "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" } ] } }
Sensitive Data Protection has found the following infoTypes, though its match confidence for each one varies:
- A phone number (unlikely)
- A US Social Security number (very likely)
- An email address (likely)
- A phone number (possible)
- A date (likely)
If you were to draw each of the bounding boxes on the image, it would look like the following. Be aware that Sensitive Data Protection often uses multiple boxes to indicate where a single instance of sensitive data is in the image.
Note that, in addition to detecting the handwritten Social Security number, the email address, and the phone number, Sensitive Data Protection has also detected the year. Assuming that's not optimal behavior, the next example demonstrates how to inspect for only certain infoTypes.
Inspecting an image for specific infoTypes
If you want to inspect an image for only certain sensitive data types, specify their corresponding built-in infoTypes.
To inspect an image for specific infoTypes:
- Encode the image as base64.
- Submit a request to the DLP API's
content.inspect
method. The request must include:- The base64-encoded image.
- One or more infoType detectors.
Consider the original image from the previous section. To inspect for only
US Social Security numbers, email addresses, and telephone numbers, send the
following JSON to the DLP API's
content.inspect
method:
C#
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST
{ "item": { "byteItem": { "data": "[BASE64-ENCODED-IMAGE]", "type": "IMAGE_JPEG" } }, "inspectConfig": { "infoTypes": [ { "name": "US_SOCIAL_SECURITY_NUMBER" }, { "name": "PHONE_NUMBER" }, { "name": "EMAIL_ADDRESS" } ] } }
Sensitive Data Protection returns the following:
{ "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" } ] } }
As you can see from the output, Sensitive Data Protection has found a US Social Security number, an email address, and a telephone number.
See the JSON quickstart for more information about using the DLP API with JSON.
Code examples
Following is sample code in several languages that demonstrates how to use Sensitive Data Protection to inspect an image for sensitive data.
C#
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.
To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Try it out
You can try each of these examples out yourself—or experiment with your
own images—in the API Explorer on the reference page for
content.inspect
:
What's next
- Learn more about image inspection and redaction.
- Learn how to redact sensitive data from images.