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

Function main

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

reidentifyDeterministicFunction · 0.85

Tested by

no test coverage detected