Checking access…

Skip to main content
Audience: CCG Platform Engineers

PayeeConfig Encryption & Key Rotation β€” Reference

Exact data, components, configuration, logs, errors, and test coverage. For the design, see the overview; for operational steps, see the runbook.

Data Model​

Where the encrypted data lives​

Payee configs are stored on the merchant aggregate:

  • VendorMerchant.payeeConfigs (type: PayeeConfigs, from wallet-event-commons)
    • defaultPayeeId
    • payees: List<PayeeConfig>

Sensitive payload is stored per payee in:

  • PayeeConfig.encryptedPayeeDetails (ciphertext or legacy plaintext)
  • PayeeConfig.keyVersion (Key Vault secret version)

PayeeConfig (wallet-event-commons)​

Stored per-payee on VendorMerchant.payeeConfigs.

FieldTypeDescription
payeeIdUUIDUnique identifier for the payee entry.
encryptedPayeeDetailsStringAES-256-GCM ciphertext prefixed with enc:v1:, or legacy plain text for pre-encryption rows.
keyVersionStringAzure Key Vault secret version used to encrypt this row; required for decryption.

PayeeConfigs (wallet-event-commons)​

Top-level container stored on VendorMerchant.

FieldTypeDescription
defaultPayeeIdUUIDThe payee used by default when none is specified on a payment.
payeesList<PayeeConfig>All payee entries for this vendor-merchant.

PayeeConfigDTO (wallet-merchant-service)​

Inbound API representation validated before encryption.

FieldConstraintsDescription
payeeNameRequired, max 35 chars, [A-Za-z0-9 !@#$%&()_+=\-;\",'./?]Payee name.
payeeAddressLine1Required, max 30 chars, [A-Za-z0-9 !@#$%&()_+=\-;\",'./?]Street address line 1.
payeeAddressLine2OptionalStreet address line 2.
payeeCityRequired, max 24 chars, letters & spaces onlyCity.
payeeStateRequired, max 2 chars, letters onlyUS state code.
payeeZipRequired, max 10 chars, alphanumericZIP / postal code.
payeeCountryRequiredCountry code.
payeePatientAccountNumberRequired, max 38 charsPatient account number used in payment routing.
payeeTaxIdRequired, max 15 chars, alphanumericPayee tax identifier.
payer835IdRequired, max 5 chars, alphanumeric835 payer ID used for claim routing.

Key Components​

PayeeEncryptionService (wallet-event-commons β€” framework-agnostic core)​

Located at com.optum.wallet.common.util.payment.vendor.crypto.PayeeEncryptionService.

Pure-Java library class with no Spring dependency. Both services wrap it with a thin @Service adapter that supplies the KeyVersionedSupplier from their own Azure Key Vault client.

MethodDescription
encrypt(String plainPayeeDetails)Encrypts the plain text using the current key version; returns ciphertext prefixed enc:v1: and the keyVersion used.
decrypt(String storedValue, String keyVersion)Decrypts an enc:v1: prefixed value with the specified key version. Returns the value unchanged for legacy plain-text rows (backward compatibility).
isEncrypted(String value)Returns true if the value starts with enc:v1:.
currentKeyVersion()Returns the current (latest) Key Vault secret version identifier.

Versioned-key design​

Every encrypted row stores the keyVersion (Azure Key Vault secret version ID) alongside the ciphertext. On decryption the service fetches that specific version from Key Vault. This enables zero-downtime key rotation: new rows are encrypted with the new version; old rows remain decryptable as long as the old version exists in the vault.

Backward compatibility​

Rows that pre-date encryption (plain-text encryptedPayeeDetails) are detected by the absence of the enc:v1: prefix and are returned as-is by decrypt(). Plaintext payee details are encrypted when the merchant is created or updated via the Merchant API. Encrypted records with a null or blank keyVersion require verified backfill or explicit re-encryption before key rotation to ensure they can be safely re-keyed.

AesGcmUtils (wallet-event-commons)​

Low-level utility that performs AES-256-GCM operations.

  • Algorithm: AES/GCM/NoPadding
  • IV: 12 random bytes generated per encryption via SecureRandom
  • GCM tag: 128 bits
  • Key size: exactly 256 bits (32 bytes); enforced at runtime
  • Wire format: Base64( IV[12] || ciphertext+tag )

KeyVersionedSupplier (wallet-event-commons)​

Interface that decouples the core encryption logic from any specific key-store SDK.

public interface KeyVersionedSupplier {
/** Returns the Base64-encoded AES-256 key for the given version. */
String getKey(String version);

/** Returns the current (latest) version identifier from the key store. */
String currentVersion();
}

Both services implement this using their Key Vault client.

Key Vault Configuration​

Vault names & secret names (by environment)​

Non-prod​

  • Key Vault: fcc-comn-chkt-kv-dev
  • Secrets (enabled):
    • ccg-payment-payee-encryption-key-dev
    • ccg-payment-payee-encryption-key-perf
    • ccg-payment-payee-encryption-key-reg
    • ccg-payment-payee-encryption-key-stage
    • ccg-payment-payee-encryption-key-test

Prod​

  • Key Vault: ccg-comn-chkt-kv-prod
  • Secret (enabled):
    • ccg-payment-payee-encryption-key

App property​

Both services reference the same Key Vault secret per environment, but use different Spring property paths:

  • wallet-merchant-service (and Event Grid webhook): merchant.payee.encryption.secret-name
  • wallet-payment-service: payment.payee.encryption.secret-name

Secret format​

The Key Vault secret value must be a Base64-encoded 256-bit (32-byte) AES key.

Generate:

openssl rand -base64 32

Store the output directly as the secret value.

Local development​

For local dev profiles (LocalKeyVaultClient), use a static Base64 key by implementing KeyVersionedSupplier with fixed values:

KeyVersionedSupplier localSupplier = new KeyVersionedSupplier() {
@Override
public String getKey(String version) { return localBase64Key; }

@Override
public String currentVersion() { return "local"; }
};

new com.optum.wallet.common.util.payment.vendor.crypto.PayeeEncryptionService(localSupplier);

Rotation Triggers​

Rotation can be initiated via:

  1. Manual REST call (internal endpoint)
  2. Azure Event Grid webhook (Key Vault secret new version)
  3. (Optional) scheduler trigger (if configured)

All triggers call: KeyRotationService.rotate("<trigger>")

Controllers / Endpoints​

Manual Trigger (REST)​

  • Controller: com.optum.wallet.merchant.controller.KeyRotationController
  • Method: POST
  • Path: /v1/encryption/key-rotation
  • Behavior: triggers keyRotationService.rotate("REST")

Response mapping (controller behavior):

ConditionKeyRotationResponse.statusHTTP status
result.latestKeyVersion() == null (advisory lock already held by another rotation)SKIPPED200 OK
result.rotated() > 0 && result.failed() == 0ROTATED202 ACCEPTED
result.failed() > 0 && result.rotated() == 0FAILED422 UNPROCESSABLE_ENTITY
result.failed() > 0 (and rotated > 0)PARTIAL202 ACCEPTED
elseUP_TO_DATE200 OK

Event Grid Webhook (Key Vault -> merchant-service)​

  • Controller: com.optum.wallet.merchant.controller.EventGridWebhookController
  • Base path: /api/eventgrid/v1.0
  • Route: POST /api/eventgrid/v1.0/keyvault-secret-event
  • Consumer: com.optum.wallet.merchant.event.consumer.keyvault.KeyVaultSecretVersionConsumer

Supported Event Grid event types:

  • Microsoft.EventGrid.SubscriptionValidationEvent
    • returns 200 OK with body containing validationResponse from the event.
  • Microsoft.KeyVault.SecretNewVersionCreated
    • triggers rotation only if the event's data.ObjectName matches ${merchant.payee.encryption.secret-name}
    • responds quickly with 202 ACCEPTED and starts rotation asynchronously

Important: rotation does not trust the version in the event payload; it fetches the latest version directly from Key Vault.

Observability (Rotation Logs)​

Rotation uses structured event= log keys (examples):

  • KEY_ROTATION_STARTED
  • KEY_ROTATION_SKIPPED
  • KEY_ROTATION_COMPLETED
  • KEY_ROTATION_FAILED
  • KEY_ROTATION_TRIGGERED
  • PAYEE_CONFIG_NOT_ENCRYPTED
  • PAYEE_CONFIG_NULL_KEY_VERSION
  • PAYEE_CONFIG_DECRYPT_FAILED
  • PAYEE_CONFIG_ENCRYPT_FAILED

Key versions should be masked in logs (e.g., only last 8 chars).

Error Handling​

All encryption/decryption failures are wrapped in PayeeCryptoException (unchecked). Common causes:

CauseException message
Blank payee details on encrypt"Payee details are empty"
Missing keyVersion for encrypted row"Missing key version for encrypted payee details"
Key Vault returns empty/null key"Encryption key is empty"
Key Vault key is not valid Base64"Encryption key is not valid Base64"
Key is not 256-bit"Invalid AES key length: N bytes"
JCE encryption failure"Failed to encrypt payee details"
JCE decryption failure"Failed to decrypt payee details"

Testing​

  • PayeeEncryptionServiceTest (commons, merchant-service, payment-service): round-trips, legacy pass-through, blank guards, invalid key detection.
  • PayeeConfigEncryptionHelperTest (merchant-service): idempotency guard, null/blank skip, full encryptAll behavior.