(projectId, alphabet, keyName, wrappedKey)
| 19 | // description: De-identify sensitive data in a string using Format Preserving Encryption (FPE). |
| 20 | // usage: node deIdentifyTableWithFpe.js my-project alphabet keyName wrappedKey |
| 21 | async function main(projectId, alphabet, keyName, wrappedKey) { |
| 22 | // [START dlp_deidentify_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 = '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 | // Table to de-identify |
| 44 | const tablularData = { |
| 45 | headers: [{name: 'Employee ID'}, {name: 'Date'}, {name: 'Compensation'}], |
| 46 | rows: [ |
| 47 | { |
| 48 | values: [ |
| 49 | {stringValue: '11111'}, |
| 50 | {stringValue: '2015'}, |
| 51 | {stringValue: '$10'}, |
| 52 | ], |
| 53 | }, |
| 54 | { |
| 55 | values: [ |
| 56 | {stringValue: '22222'}, |
| 57 | {stringValue: '2016'}, |
| 58 | {stringValue: '$20'}, |
| 59 | ], |
| 60 | }, |
| 61 | { |
| 62 | values: [ |
| 63 | {stringValue: '33333'}, |
| 64 | {stringValue: '2016'}, |
| 65 | {stringValue: '$15'}, |
| 66 | ], |
| 67 | }, |
| 68 | ], |
| 69 | }; |
| 70 | |
| 71 | async function deidentifyTableWithFpe() { |
| 72 | // Specify field to be encrypted. |
| 73 | const fieldIds = [{name: 'Employee ID'}]; |
| 74 | |
| 75 | // Specify an encrypted AES-256 key and the name of the Cloud KMS key that encrypted it |
| 76 | const cryptoKeyConfig = { |
| 77 | kmsWrapped: { |
| 78 | wrappedKey: wrappedKey, |
nothing calls this directly
no test coverage detected