Inspect images for sensitive data

This document describes how to use the Cloud Data Loss Prevention API to detect sensitive text and objects in an image. Sensitive Data Protection returns the location of any sensitive data that it detects.

Given an image as input, Sensitive Data Protection detects sensitive data in the image. The output of an inspection operation includes the detected infoTypes, the likelihood of the match, and pixel coordinates 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).

Inspect an image for all default infoTypes

To inspect an image for sensitive data, you submit a base64-encoded image to the content.inspect method. If you don't specify specific information types (infoTypes) to search for, Sensitive Data Protection searches for the most common infoTypes.

To inspect an image for all default infoTypes, follow these steps:

  1. Encode the image as base64.
  2. Submit a request to the content.inspect method of the DLP API. The request requires only the base64-encoded image.

For example, consider this image of a document.

Original image that contains a person's contact information.
Original image (click to enlarge).

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.


using System;
using System.IO;
using System.Linq;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dlp.V2;
using Google.Protobuf;

public class InspectImageForSensitiveDataWithInfoTypes
{
    public static InspectContentResponse InspectImage(
        string projectId,
        string filePath)
    {
        // Instantiate dlp client.
        var dlp = DlpServiceClient.Create();

        // Construct the content item.
        var contentItem = new