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

Function main

dlp/reidentifyWithFpeSurrogate.js:21–103  ·  view source on GitHub ↗
(projectId, string, alphabet, surrogateType, unwrappedKey)

Source from the content-addressed store, hash-verified

19// description: Re-identify sensitive data in a string using Format Preserving Encryption (FPE) with surrogate.
20// usage: node reidentifyWithFpeSurrogate.js my-project string alphabet infoTypes surrogateType unwrappedKey
21function main(projectId, string, alphabet, surrogateType, unwrappedKey) {
22 // [START dlp_reidentify_free_text_with_fpe_using_surrogate]
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 Re-identify
33 // const string = 'PHONE_TOKEN(10):########';
34
35 // The set of characters to replace sensitive ones with
36 // For more information, see https://cloud.google.com/dlp/docs/reference/rest/v2/organizations.deidentifyTemplates#ffxcommonnativealphabet
37 // const alphabet = 'NUMERIC';
38
39 // InfoTypes
40 // const infoTypes = [{name: 'PHONE_NUMBER'}];
41
42 // Surrogate Type
43 // const surrogateType = 'PHONE_TOKEN';
44
45 // The base64-encoded AES-256 key to use
46 // const unwrappedKey = 'YWJjZGVmZ2hpamtsbW5vcA==';
47
48 async function reidentifyWithFpeSurrogate() {
49 // Specify an unwrapped crypto key.
50 unwrappedKey = Buffer.from(unwrappedKey, 'base64');
51
52 // Specify how the info from the inspection should be encrypted.
53 const cryptoReplaceFfxFpeConfig = {
54 cryptoKey: {
55 unwrapped: {
56 key: unwrappedKey,
57 },
58 },
59 commonAlphabet: alphabet,
60 surrogateInfoType: {name: surrogateType},
61 };
62
63 // Construct the inspect configuration.
64 const inspectConfig = {
65 customInfoTypes: [
66 {
67 infoType: {
68 name: surrogateType,
69 },
70 surrogateType: {},
71 },
72 ],
73 };
74
75 // Set the text to be re-identified.
76 const item = {value: string};
77
78 // Combine configurations into a request for the service.

Callers 1

Calls 1

Tested by

no test coverage detected