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

Function main

dlp/reidentifyTableWithFpe.js:21–100  ·  view source on GitHub ↗
(projectId, alphabet, keyName, wrappedKey)

Source from the content-addressed store, hash-verified

19// description: Re-identify sensitive data in a string using Format Preserving Encryption (FPE).
20// usage: node reidentifyTableWithFpe.js my-project alphabet keyName wrappedKey
21async function main(projectId, alphabet, keyName, wrappedKey) {
22 // [START dlp_reidentify_table_fpe]
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 set of characters to replace sensitive ones with
33 // For more information, see https://cloud.google.com/dlp/docs/reference/rest/v2/organizations.deidentifyTemplates#ffxcommonnativealphabet
34 // const alphabet = 'ALPHA_NUMERIC';
35
36 // The name of the Cloud KMS key used to encrypt ('wrap') the AES-256 key
37 // const keyName = 'projects/YOUR_GCLOUD_PROJECT/locations/YOUR_LOCATION/keyRings/YOUR_KEYRING_NAME/cryptoKeys/YOUR_KEY_NAME';
38
39 // The encrypted ('wrapped') AES-256 key to use
40 // This key should be encrypted using the Cloud KMS key specified above
41 // const wrappedKey = 'YOUR_ENCRYPTED_AES_256_KEY'
42
43 // The name of the surrogate custom info type to use when reidentifying data
44 // const surrogateType = 'SOME_INFO_TYPE_DEID';
45
46 // Table to re-identify
47 const tablularData = {
48 headers: [{name: 'Employee ID'}],
49 rows: [{values: [{stringValue: '90511'}]}],
50 };
51
52 async function reidentifyTableWithFpe() {
53 // Specify field to be re-identified.
54 const fieldIds = [{name: 'Employee ID'}];
55
56 // Specify an encrypted AES-256 key and the name of the Cloud KMS key that encrypted it
57 const cryptoKeyConfig = {
58 kmsWrapped: {
59 wrappedKey: wrappedKey,
60 cryptoKeyName: keyName,
61 },
62 };
63
64 // Associate transformation with crypto key congurations.
65 const primitiveTransformation = {
66 cryptoReplaceFfxFpeConfig: {
67 cryptoKey: cryptoKeyConfig,
68 commonAlphabet: alphabet,
69 },
70 };
71
72 // Combine configurations into a request for the service.
73 const request = {
74 parent: `projects/${projectId}/locations/global`,
75 reidentifyConfig: {
76 recordTransformations: {
77 fieldTransformations: [
78 {

Callers

nothing calls this directly

Calls 1

reidentifyTableWithFpeFunction · 0.85

Tested by

no test coverage detected