Checking access…

Skip to main content
Audience: CCG Platform Engineers

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.

  1. Merchant API receives a VendorMerchant payload containing a PayeeConfigs object with plain-text payee details in encryptedPayeeDetails.
  2. MerchantService delegates to PayeeConfigEncryptionHelper.encryptAll(PayeeConfigs).
  3. 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.
  4. Stores the encrypted VendorMerchant and publishes a MerchantEvent containing encrypted PayeeConfigs.

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.

  1. MerchantConsumer receives MerchantEvent and persists the PayeeConfigs (already encrypted) onto the Merchant entity β€” no decryption at this stage.
  2. CreateUserPaymentCommandHandler decrypts payee details at payment-processing time via PayeeEncryptionService.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 PayeeConfig is retained unchanged.

Common cases:

  • Legacy plaintext (encryptedPayeeDetails missing enc: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 MerchantEvent of type MERCHANT_UPDATED_EVENT so downstream consumers ( payment-service) converge on the new keyVersion values.