Step 2: Encrypt Customer PII Data
The pattern you used to encrypt credit card numbers can be applied to any piece of Personally Identifiable Information (PII). In this step, you will extend your pipeline to also encrypt the ssn and email fields.
The Goal
You will enhance your existing processor to also:
- Encrypt the
ssnandemailfields. - Extract
ssn_last_fourandemail_domainfor analytics. - Delete the original
ssnandemailfields.
Implementation
-
Start with the Previous Pipeline: Copy the
encrypt-card.yamlfile from Step 1 to a new file namedencrypt-pii.yaml.cp encrypt-card.yaml encrypt-pii.yaml -
Inspect the maintained mapping: Review the selected fields, key lookup, and plaintext removal in the linked reference before adapting the processor.
See the complete configuration for the maintained encryption mapping and its ciphertext fields.
Note: Use the key variable names from the configuration you are adapting.
-
Deploy and Test:
# Send the sample payment data, which includes a customer object
curl -X POST http://localhost:8080/events/payment \
-H "Content-Type: application/json" \
-d @/tmp/encryption-test/sample-payment.json -
Verify: Check your logs. You will see that in addition to the encrypted card number, the
customerobject now containsssn_encrypted,ssn_last_four,email_encrypted, andemail_domain, while the originalssnandemailfields have been removed.
The existing processor now handles the additional PII fields. You can repeat this pattern for other sensitive fields.