PayeeConfig Encryption & Key Rotation
Platform engineers understanding the encryption and rotation design. For exact fields and configuration, see the reference. For rotation and incident procedures, see the runbook. See Session Cookie Encryption for the related encryption pattern.
Overviewβ
Payee configuration data (address, tax ID, patient account number, payer 835 ID, etc.) contains sensitive PII/PHI. To protect this data at rest, Convenient Checkout encrypts the serialized payee details using AES-256-GCM before persisting them in the database.
Keys are stored in Azure Key Vault (never in source code or app config). Each encrypted payee record also stores the Key Vault secret version used to encrypt it, enabling zero-downtime key rotation.
Architectureβ
+-----------------------------------------------------------------------+
| wallet-merchant-service |
| |
| Write path (encrypt-on-save) |
| Merchant API -> MerchantService |
| -> PayeeConfigEncryptionHelper.encryptAll(...) |
| -> PayeeEncryptionService.encrypt(...) |
| -> KeyVersionedSupplier (Azure Key Vault) |
| |
| Rotation path (re-encrypt stale versions) |
| KeyRotationService.rotate(trigger) |
| -> PostgreSQL advisory lock (cluster-wide singleton) |
| -> Re-encrypt stale payees to latest key version |
| -> Publish MerchantEvent (MERCHANT_UPDATED_EVENT) |
+-----------------------------------+-----------------------------------+
|
| MerchantEvent (PayeeConfigs encrypted)
v
+-----------------------------------------------------------------------+
| wallet-payment-service |
| |
| Ingest path |
| MerchantConsumer persists PayeeConfigs as received (encrypted) |
| |
| Runtime path (decrypt-on-use) |
| CreateUserPaymentCommandHandler |
| -> PayeeEncryptionService.decrypt(..., keyVersion) |
| -> KeyVersionedSupplier (Azure Key Vault) |
+-----------------------------------------------------------------------+
--- wallet-event-commons (shared library) ---
PayeeEncryptionService (core logic)
AesGcmUtils (AES-256-GCM)
KeyVersionedSupplier (KV abstraction)
PayeeConfig / PayeeConfigs (POJOs)
Service Responsibilitiesβ
wallet-merchant-serviceβ
Responsibility: encrypt payee details on write.
- Merchant API receives a
VendorMerchantpayload containing aPayeeConfigsobject with plain-text payee details inencryptedPayeeDetails. MerchantServicedelegates toPayeeConfigEncryptionHelper.encryptAll(PayeeConfigs).- The helper iterates each
PayeeConfig:- Skips entries where details are blank.
- Skips entries already prefixed with
enc:v1:(idempotent re-saves). - Calls
PayeeEncryptionService.encrypt(details)for all other entries.
- Stores the encrypted
VendorMerchantand publishes aMerchantEventcontaining encryptedPayeeConfigs.
Spring adapter (merchant-service)
- Property:
merchant.payee.encryption.secret-name - Strips trailing whitespace/newlines from Key Vault secret values before Base64 decoding.
wallet-payment-serviceβ
Responsibility: store encrypted payee configs and decrypt on payment processing.
MerchantConsumerreceivesMerchantEventand persists thePayeeConfigs(already encrypted) onto theMerchantentity β no decryption at this stage.CreateUserPaymentCommandHandlerdecrypts payee details at payment-processing time viaPayeeEncryptionService.decrypt(encryptedPayeeDetails, keyVersion).
Sequencesβ
Sequence: Merchant Save (Encrypt)β
Client -> MerchantController
-> MerchantService.saveMerchant(vendorMerchant)
-> PayeeConfigEncryptionHelper.encryptAll(payeeConfigs)
-> [for each PayeeConfig]
-> PayeeEncryptionService.isEncrypted(details) -> false
-> PayeeEncryptionService.encrypt(details)
-> KeyVault currentVersion() -> version
-> KeyVault getKey(version) -> base64Key
-> AesGcmUtils.encrypt(details, aesKey) -> ciphertext
-> store PayeeConfig(enc:v1:<payload>, version)
-> save encrypted VendorMerchant
-> publish MerchantEvent (encrypted)
Sequence: Payment Processing (Decrypt)β
PaymentCommand -> CreateUserPaymentCommandHandler
-> merchantRepository.findMerchant(...)
-> PayeeEncryptionService.decrypt(encryptedPayeeDetails, keyVersion)
-> isEncrypted? -> yes (enc:v1: prefix)
-> KeyVault getKey(keyVersion) -> base64Key
-> AesGcmUtils.decrypt(cipherPayload, aesKey) -> plainText
-> use plain-text payee details for payment routing
Key Rotation (merchant-service)β
Purposeβ
Rotation rewrites payee configs encrypted with stale Key Vault secret versions so the dataset converges to the latest version.
Implementation:
com.optum.wallet.merchant.service.KeyRotationService
What βstaleβ meansβ
A merchant needs rotation if any payee has:
payee.keyVersion != latestKeyVersion
Concurrency control (cluster-wide singleton)β
Rotation is guarded by a PostgreSQL advisory lock (one rotation at a time across the cluster):
- lock name/resource:
merchant-service:key-rotation
If lock is already held, rotation is skipped.
Safety rules during rotationβ
Rotation is non-destructive:
- If a payee cannot be safely rotated, the original
PayeeConfigis retained unchanged.
Common cases:
- Legacy plaintext (
encryptedPayeeDetailsmissingenc:v1:): not rotated (logged as not encrypted). - Encrypted but missing
keyVersion: rotation may probe decryption; if it canβt decrypt reliably, it leaves the payee unchanged.
Persistence and downstream propagationβ
- Merchants are saved only if at least one payee was re-encrypted.
- After saving, merchant-service publishes
MerchantEventof typeMERCHANT_UPDATED_EVENTso downstream consumers ( payment-service) converge on the newkeyVersionvalues.