MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dlp/deidentifyWithDeterministic.js:21–110  ·  view source on GitHub ↗
(
  projectId,
  string,
  infoTypes,
  keyName,
  wrappedKey,
  surrogateType
)

Source from the content-addressed store, hash-verified

19// description: De-identify sensitive data in a string using deterministic encryption, which is a reversible cryptographic method.
20// usage: node deidentifyWithDeterministic.js my-project string infoTypes keyName wrappedKey surrogateType
21async function main(
22 projectId,
23 string,
24 infoTypes,
25 keyName,
26 wrappedKey,
27 surrogateType
28) {
29 infoTypes = transformCLI(infoTypes);
30 // [START dlp_deidentify_deterministic]
31 // Imports the Google Cloud Data Loss Prevention library
32 const DLP = require('@google-cloud/dlp');
33
34 // Instantiates a client
35 const dlp = new DLP.DlpServiceClient();
36
37 // The project ID to run the API call under
38 // const projectId = 'my-project';
39
40 // The string to deidentify
41 // const string = 'My name is Alicia Abernathy, and my email address is aabernathy@example.com.';
42
43 // The infoTypes of information to match
44 // const infoTypes = [{ name: 'EMAIL_ADDRESS' }];
45
46 // The name of the Cloud KMS key used to encrypt ('wrap') the AES-256 key
47 // const keyName = 'projects/YOUR_GCLOUD_PROJECT/locations/YOUR_LOCATION/keyRings/YOUR_KEYRING_NAME/cryptoKeys/YOUR_KEY_NAME';
48
49 // The encrypted ('wrapped') AES-256 key to use
50 // This key should be encrypted using the Cloud KMS key specified above
51 // const wrappedKey = 'YOUR_ENCRYPTED_AES_256_KEY'
52
53 // The name of the surrogate custom info type to use
54 // Only necessary if you want to reverse the deidentification process
55 // Can be essentially any arbitrary string, as long as it doesn't appear
56 // in your dataset otherwise.
57 // const surrogateType = 'EMAIL_ADDRESS_TOKEN';
58
59 async function deidentifyDeterministic() {
60 // Specify an encrypted AES-256 key and the name of the Cloud KMS key that encrypted it
61 const cryptoDeterministicEncryption = {
62 cryptoKey: {
63 kmsWrapped: {
64 wrappedKey: wrappedKey,
65 cryptoKeyName: keyName,
66 },
67 },
68 surrogateInfoType: {name: surrogateType},
69 };
70
71 // Construct inspect configuration to match information
72 const inspectConfig = {
73 infoTypes,
74 };
75
76 // Associate the encryption with the infotype transformation.
77 const infoTypeTransformations = {
78 transformations: [

Callers

nothing calls this directly

Calls 2

deidentifyDeterministicFunction · 0.85
transformCLIFunction · 0.70

Tested by

no test coverage detected