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

Function main

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

Source from the content-addressed store, hash-verified

19// description: De-identify sensitive data in a string using Format Preserving Encryption (FPE) with surrogate.
20// usage: node deidentifyWithFpeSurrogate.js my-project string alphabet infoTypes surrogateType unwrappedKey
21function main(
22 projectId,
23 string,
24 alphabet,
25 infoTypes,
26 surrogateType,
27 unwrappedKey
28) {
29 infoTypes = transformCLI(infoTypes);
30 // [START dlp_deidentify_free_text_with_fpe_using_surrogate]
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 de-identify
41 // const string = 'My phone number is 4359916732';
42
43 // The set of characters to replace sensitive ones with
44 // For more information, see https://cloud.google.com/dlp/docs/reference/rest/v2/organizations.deidentifyTemplates#ffxcommonnativealphabet
45 // const alphabet = 'NUMERIC';
46
47 // InfoTypes
48 // const infoTypes = [{name: 'PHONE_NUMBER'}];
49
50 // Surrogate Type
51 // const surrogateType = 'PHONE_TOKEN';
52
53 // The base64-encoded AES-256 key to use
54 // const unwrappedKey = 'YWJjZGVmZ2hpamtsbW5vcA==';
55
56 async function deidentifyWithFpeSurrogate() {
57 // Specify an unwrapped crypto key.
58 unwrappedKey = Buffer.from(unwrappedKey, 'base64');
59
60 // Specify how the info from the inspection should be encrypted.
61 const cryptoReplaceFfxFpeConfig = {
62 cryptoKey: {
63 unwrapped: {
64 key: unwrappedKey,
65 },
66 },
67 commonAlphabet: alphabet,
68 surrogateInfoType: {name: surrogateType},
69 };
70
71 // Construct the inspect configuration.
72 const inspectConfig = {
73 infoTypes: infoTypes,
74 minLikelihood: DLP.protos.google.privacy.dlp.v2.Likelihood.UNLIKELY,
75 };
76
77 // Set the text to be de-identified.
78 const item = {value: string};

Callers 1

Calls 2

transformCLIFunction · 0.70

Tested by

no test coverage detected