Payment Cryptography
Payment Cryptography provides an AWS-compatible API for regional payment keys, aliases, tags, protected key exchange, and payment data operations. It validates control-plane and data-plane request shapes, keeps aliases stable during a request, and applies key purpose and state rules before it performs cryptographic work.
Service boundary
The service exposes a JSON control plane selected by the AWS target header. It also exposes payment data operations through the shared service routing layer. The control plane manages key records and aliases. The data plane uses eligible keys for encryption, MAC, PIN, card validation, authorization cryptograms, and AS2805 key-encryption-key validation.
The shared request envelope and authentication checks are described in Request routing and protocols and IAM and auth. This page focuses on the payment service contract after a request reaches the service.
Capability groups
The API groups its behavior around resource state, protected key exchange, key-encryption-key checks, and payment calculations:
| Capability | Purpose |
|---|---|
| Key management | Create, read, list, delete, import, and export regional key records. |
| Alias management | Create, read, list, move, detach, and delete names that point to keys. |
| Tag management | Add, remove, and list tags on keys. |
| Key exchange | Protect key material with TR-31 blocks, RSA key cryptograms, TR-34 signed blocks, AS2805 cryptograms, or ECDH-derived protection. |
| Certificate support | Return public-key certificates and validate certificates used by key exchange. |
| Data operations | Encrypt, decrypt, re-encrypt, create or verify MACs, process PIN data, validate cards, and process authorization cryptograms. |
| KEK validation | Prove that two parties hold the same AS2805 key-encryption key. |
References: src/…/PaymentCryptographyJsonHandler.java• L19-79 src/…/PaymentCryptographyService.java• L35-44 src/…/PaymentCryptographyKeyExchange.java• L39-82 src/…/PaymentCryptographyKekValidationController.java• L12-35
Resource state
Payment Cryptography keeps keys and aliases as separate regional resources. A key owns its attributes, state, enabled flag, export policy, check value, and tags. An alias owns its name and optional key reference.
Key lifecycle
Key creation binds an algorithm and key class to a declared payment purpose. The service creates or imports the matching material, records whether the key is enabled and exportable, and returns metadata with a check value rather than raw symmetric material. Symmetric keys use an algorithm-specific check value. Asymmetric keys use the fixed 000000 value because a key pair has no symmetric check value.
Deletion is immediate in the emulator. The delete response shows DELETE_PENDING, a disabled key, and a pending-deletion time. The key is then absent from later lookups, and aliases attached to it are removed.
Data operations require an enabled key with a compatible purpose, algorithm family, mode of use, and available material. Symmetric material remains available only for the running service process, while key records and metadata are stored.
References: src/…/PaymentCryptographyService.java• L144-272 src/…/PaymentCryptographyService.java• L331-360 src/…/PaymentCryptographyJsonHandler.java• L83-121
Alias state
An alias name is unique within a region. Key operations can resolve a key by key ARN, alias ARN, or alias name. Alias operations name a target key with KeyArn, while tag operations name a key with ResourceArn.
An alias must point to a key when it is created. An update can move it to another key in the same region or detach it by omitting KeyArn. A detached alias remains addressable without a KeyArn until it is updated or deleted.
The relationship changes through this path:
flowchart LR
CreateKey[Create key] --> CreateAlias[Create alias]
CreateAlias --> KeyA[Key A]
KeyA -->|UpdateAlias with KeyArn| KeyB[Key B]
KeyB -->|UpdateAlias without KeyArn| Detached[Detached alias]
KeyA -->|DeleteKey| Removed[Key and attached aliases removed]
References: src/…/PaymentCryptographyService.java• L363-473 src/…/PaymentCryptographyJsonHandler.java• L171-230
Regional scope
Keys, aliases, and tags belong to the region where they are created. The region forms part of resource identity, so an ARN from another region does not resolve in the current request. Tags remain local to the regional key record.
References: src/…/PaymentCryptographyService.java• L35-42 src/…/PaymentCryptographyService.java• L275-302 src/…/PaymentCryptographyService.java• L1010-1063
Request shape handling
The service checks each supported request against the AWS Payment Cryptography model before it changes state or performs cryptographic work. The checks cover required members, types, lengths, patterns, ranges, and enum values. Invalid input returns ValidationException.
Identifier members
The request member used to identify a resource is part of the API contract. Reading the same member for lookup and authorization keeps the named resource consistent.
| Operation group | Resource member | Accepted form |
|---|---|---|
| Key operations | KeyIdentifier | Key ARN, alias ARN, or alias name. |
| Alias operations | KeyArn | Key ARN for the target key. |
| Tag operations | ResourceArn | Key ARN. |
| Data operations | Operation-specific key member | The key role named by the operation. |
References: src/…/PaymentCryptographyRequestShapes.java• L7-37 src/…/PaymentCryptographyDataRequestShapes.java• L7-34 src/…/PaymentCryptographyJsonHandler.java• L322-341
Attribute unions
Many payment requests use a union: a set of named variants where exactly one variant selects the request meaning. The service rejects a union with no variant or more than one variant. It also rejects unsupported payment schemes instead of treating them as a different supported scheme.
The selected variant then controls the required payment inputs and key rules. Card validation variants select static or dynamic card data, authorization variants select the derivation scheme and response form, and KEK validation selects either the initiating request or the response form.
References: src/…/PaymentCryptographyCardValidationOperations.java• L167-225 src/…/PaymentCryptographyAuthCryptogramOperations.java• L135-169 src/…/PaymentCryptographyKekValidationOperations.java• L67-80 src/…/PaymentCryptographyJsonHandler.java• L496-515
Request member conversion
Control-plane and data-plane handlers use one member conversion rule before they call service logic. Objects become nested maps, arrays become nested lists, booleans stay booleans, and JSON null means that the member is absent rather than the text "null".
This shared view keeps nested key-material forms and data-operation attributes consistent across the two API protocols. It also keeps the request member order when the service passes a request onward for key-material translation.
References: src/…/PaymentCryptographyMembers.java• L10-64
Key material forms
Import and export requests also use a one-form union. The selected form states how the key is protected and which counterparty information is needed.
| Form | Role in the exchange |
|---|---|
Tr31KeyBlock | Carries a key under a key encryption or key block protection key. |
KeyCryptogram | Carries symmetric key material under an RSA certificate. |
Tr34KeyBlock | Carries a signed and enveloped TR-31 block for a receiving device. |
DiffieHellmanTr31KeyBlock | Carries a TR-31 block under a key derived from ECDH and a KDF. |
As2805KeyCryptogram | Carries a TDES key under a TDES key encryption key with a purpose-bound AS2805 variant. |
RootCertificatePublicKey | Imports a public key from a certificate that stands on its own. |
TrustedCertificatePublicKey | Imports a public key from a certificate signed by a named authority. |
The service rejects forms outside the operation's supported set. Import and export parameters provide short-lived certificates and tokens for the supported exchange paths. A valid token remains usable until it expires, and parameter requests can reuse a still-valid issued value. The service keeps these exchange values in running process state and sweeps expired values.
References: src/…/PaymentCryptographyJsonHandler.java• L38-45 src/…/PaymentCryptographyKeyExchange.java• L66-117 src/…/PaymentCryptographyKeyExchange.java• L1233-1341
List responses
Key, alias, and tag listings support MaxResults and NextToken. ListKeys can filter by key state. When no state is supplied, it lists all keys in the current region.
References: src/…/PaymentCryptographyJsonHandler.java• L142-157 src/…/PaymentCryptographyJsonHandler.java• L196-210 src/…/PaymentCryptographyService.java• L304-328
Cryptographic operations
The cryptographic layer supplies the primitives and payment rules used by the data plane and key exchange. Each operation first checks that the key purpose and mode match the requested work. The service refuses a scheme it cannot implement rather than returning a value with a different meaning.
Key check values
Key check values give callers a short way to identify symmetric key material without exposing the material itself. AES keys use an AES-CMAC check value, TDES keys use the payment TDES check rule, and keyed-hash keys use a hash-based check value. Asymmetric records keep the fixed non-symmetric value described by the service model.
References: src/…/PaymentCryptographyCrypto.java• L12-24 src/…/PaymentCryptographyCrypto.java• L68-115
Symmetric data operations
The data plane supports AES and TDES symmetric encryption with the modes named by the request: ECB, CBC, CFB, CFB1, CFB8, CFB64, CFB128, and OFB. It does not add padding, so block-mode input must fill whole cipher blocks. Modes that use feedback take an initialization vector; ECB does not.
The cipher family comes from the key. AES uses a sixteen-byte block and vector, while TDES uses an eight-byte block and vector. Re-encryption decrypts with the incoming key and mode, then encrypts with the outgoing key and mode. The service rejects a mode whose feedback width is wider than the selected cipher.
References: src/…/PaymentCryptographyCryptoHandler.java• L82-157 src/…/PaymentCryptographyCryptoHandler.java• L249-351 src/…/PaymentCryptographyCrypto.java• L216-369 src/…/BlockMode.java• L8-19 src/…/Cfb1.java• L10-21
MAC operations
MAC operations support ISO 9797 algorithms, AES CMAC, HMAC, and selected DUKPT-derived ISO 9797 paths. The requested algorithm selects the key family and the mode of use. MAC length is expressed as hexadecimal characters for the fixed-width payment MACs; HMAC returns its full hash output.
A failed comparison returns VerificationFailedException, not a successful response containing false. DUKPT, or derived unique key per transaction, turns a base derivation key and a key serial number into a transaction MAC key.
References: src/…/PaymentCryptographyCryptoHandler.java• L160-204 src/…/PaymentCryptographyCryptoHandler.java• L454-589 src/…/DukptCrypto.java• L6-17 src/…/DukptCrypto.java• L32-122
PIN and card validation operations
PIN operations support Visa PIN verification values and PIN-block generation, verification, and translation. ISO format 0 and 3 use TDES blocks. ISO format 4 uses an AES block. DUKPT derives a TDES PIN key from a base derivation key and a key serial number.
PIN generation can create a fresh four-digit PIN or compute a verification value from a supplied encrypted block. PIN translation decrypts under an incoming PIN-encryption key and re-encrypts under an outgoing key. It keeps the account number unchanged and can derive either working key through the supported TDES DUKPT path. A malformed or unreadable PIN block is an invalid request, while a well-formed PIN that does not match the verification value returns VerificationFailedException. Unsupported IBM 3624, AS2805 PIN translation, and EMV PIN-change paths are refused.
Card validation operations calculate or verify static values from the account number and card data. Dynamic card validation also uses transaction counters and a derived card key. The proprietary dynamic card verification code path is refused.
References: src/…/PaymentCryptographyPinOperations.java• L25-41 src/…/PaymentCryptographyPinOperations.java• L97-169 src/…/PaymentCryptographyPinOperations.java• L172-260 src/…/PaymentCryptographyPinOperations.java• L282-446 src/…/PaymentCryptographyCardValidationOperations.java• L59-165 src/…/PaymentCryptographyCardValidationOperations.java• L172-224
KEK validation
AS2805 key-encryption-key validation is a two-party ceremony that lets each side prove it holds the same TDES key without sending that key. The data-plane operation accepts one of two KekValidationType forms: a sender creates the challenge and expected answer, while a responder opens the challenge and creates the answer.
The sender uses a random value of 8, 16, or 24 bytes. If the request omits the length, the service uses 16 bytes. It adjusts the value to odd parity, encrypts it under the selected 82 or 82C0 key variant, and prepares the expected result by inverting the value and encrypting it under the matching 84 or 84C0 variant. The responder decrypts the received value with the send variant and applies the same inversion and receive-variant encryption. Both forms return the key ARN, its check value, and the send and receive values.
The named key must be a TDES key-encryption key with the required encryption or decryption mode. The optional declared derivation algorithm must match that key. The service performs the operation through GenerateAs2805KekValidation at the data-plane route /as2805kekvalidation/generate.
This diagram shows the challenge and response relationship between the two parties.
sequenceDiagram
participant A as Initiating party
participant S as Payment Cryptography
participant B as Responding party
A->>S: Generate KekValidationRequest
S-->>A: RandomKeySend and expected RandomKeyReceive
A->>B: Send RandomKeySend
B->>S: Generate KekValidationResponse
S-->>B: RandomKeyReceive
B-->>A: Return RandomKeyReceive
A->>A: Compare received and expected values
References: src/…/PaymentCryptographyKekValidationController.java• L12-35 src/…/PaymentCryptographyKekValidationOperations.java• L18-120 src/…/PaymentCryptographyKekValidation.java• L8-24
Authorization cryptograms
Authorization cryptogram requests derive an ICC master key from account data. They may derive a session key from the transaction counter and then calculate an authorization request cryptogram over the caller's transaction data. Verification can also calculate an authorization response cryptogram when the request supplies response attributes.
The supported choices are EMV common, Mastercard, and Visa Smart Debit. American Express and EMV 2000 derivations are refused because their required derivation rules are not implemented.
This diagram shows the shared path from the issuer key to an authorization result.
flowchart LR
IMK[Issuer master key] --> MK[ICC master key]
PAN[PAN and sequence] --> MK
MK --> SK[Session key or direct scheme key]
ATC[Transaction inputs] --> SK
TX[Transaction data] --> ARQC[ARQC]
SK --> ARQC
ARQC --> Verify[Verify ARQC]
ARQC --> ARPC[Optional ARPC]
References: src/…/PaymentCryptographyAuthCryptogramOperations.java• L21-39 src/…/PaymentCryptographyAuthCryptogramOperations.java• L96-205 src/…/EmvCrypto.java• L124-149 src/…/EmvCrypto.java• L199-295
Key exchange cryptography
Export protects a key according to the requested form and the receiving party's key or certificate. Import authenticates and unwraps that form, then creates a key record with the recovered attributes and material. Exportability and key strength limit what protection may be used.
TR-31 blocks carry key purpose, modes, algorithm family, and exportability with authenticated key material. RSA key cryptograms use OAEP with SHA-256 or SHA-512. TR-34 adds a signed and enveloped block for a receiving device. Its content is encrypted under an ephemeral key, the ephemeral key is wrapped for the receiver, and the signed attributes bind the envelope, nonce, and TR-31 header. ECDH exchange requires compatible elliptic-curve keys and derives protection material with either the NIST concatenation KDF or ANSI X9.63 KDF. AS2805 uses purpose-specific variants to bind a carried TDES key to its payment purpose. The variant must match the key usage during export and supplies the usage during import.
Certificates may arrive as PEM, base64-encoded PEM, or base64-encoded DER. The service checks a trusted certificate's signature and validity window before it uses the certificate for key exchange. For generated asymmetric keys, certificate requests use the key's public half and a signature from its private half. The subject is built from the request's named fields and the requested digest.
References: src/…/PaymentCryptographyKeyExchange.java• L224-327 src/…/PaymentCryptographyKeyExchange.java• L341-399 src/…/PaymentCryptographyKeyExchange.java• L1408-1444 src/…/PaymentCryptographyKeyExchange.java• L1482-1605 src/…/PaymentCryptographyAs2805Variant.java• L7-34 src/…/PaymentCryptographyCertificateRequest.java• L23-31 src/…/PaymentCryptographyCertificateRequest.java• L68-135 src/…/Tr34.java• L35-54 src/…/Tr34.java• L158-252 src/…/Tr34.java• L326-475
Request context
The service uses request-scoped context to keep an alias resolution stable across authorization and execution. This prevents one request from being checked against one key and then acting on another after a concurrent alias update.
Alias resolution consistency
When a request first resolves an alias, the context records the key that the alias named in that region. Later lookups in the same request use that recorded identity. A missing alias target is also remembered as empty, so the request does not acquire a new target during its work.
The consistency boundary is:
sequenceDiagram
participant R as Request
participant C as Request context
participant A as Alias state
participant I as IAM/resource check
participant S as Service action
R->>A: Resolve alias
A-->>C: Store key identity
C->>I: Use pinned key
Note over A,C: Alias may move after resolution
C->>S: Use the same pinned key
References: src/…/PaymentCryptographyService.java• L371-393 src/…/PaymentCryptographyJsonHandler.java• L331-341
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the operation dispatch, request-shape model, and supported key-material forms aligned.
- Preserve the identifier-member mapping so lookup and authorization use the same resource.
- Preserve region in key and alias identity rules. Alias names must not become global.
- Keep deletion and tag updates safe against writing a deleted key back to storage.
- Keep key purpose, algorithm family, modes, exportability, and strength checks aligned with each operation.
- Keep union variants aligned with the cryptographic inputs and key rules they select.
- Keep exchange token and certificate lifetime rules aligned with import and export flows.
- Keep TR-31 headers, TR-34 signed content, AS2805 variants, and recovered key attributes aligned.
- Keep raw material out of key responses and persistent metadata while preserving the material needed by the running data plane.
- Keep the advertised symmetric modes aligned with IV rules, feedback widths, and the AES or TDES block size.
- Keep PIN-block format, PIN-key family, DUKPT derivation, and Visa PVV rules aligned.
- Keep KEK validation request and response forms aligned with the variant masks, random lengths, TDES key family, and key modes.
- Keep certificate-request subject fields and signature algorithms aligned with the certificate API model.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A request uses the wrong identifier member or a key ID where an ARN or alias is required | Shape validation or lookup rejects the request. | Use the member and identifier form defined for that operation. |
| A data-plane key is disabled or has the wrong purpose, mode, algorithm, or material | The cryptographic operation is refused. | Use an enabled key created or imported for the requested operation. |
| A union names zero or multiple variants | The service cannot determine the request meaning. | Supply exactly one supported variant. |
| CBC or other block-mode data is not block-aligned | Encryption or decryption fails because the service adds no padding. | Supply complete blocks for the selected cipher. |
| A feedback mode is wider than the key's cipher block | The request is refused before cipher work. | Match the mode to the AES or TDES key family. |
| An initialization vector has the wrong length or is supplied to ECB | The symmetric operation returns ValidationException. | Use no IV for ECB and use the selected cipher's block length for other modes. |
| A key block has the wrong family, strength, MAC, or exportability | Import or export returns ValidationException. | Use a compatible protection key and preserve the key's allowed policy. |
| An RSA cryptogram uses an invalid token, certificate, digest, or key length | The key cannot be imported or exported. | Use an unexpired token, a valid trusted certificate, and the matching OAEP specification. |
| A TR-34 block has an invalid signature, digest, nonce, certificate chain, or clear header | The signed key exchange is refused. | Use the issued exchange token and keep the signed block, nonce, certificates, and header aligned. |
| ECDH peers use different curves or unsupported KDF settings | Key agreement is refused. | Use matching curves and a supported KDF, hash, and shared-information value. |
| An AS2805 variant does not match the key purpose or the wrapping key is not a TDES key encryption key | The key cryptogram is refused. | Use the variant for the key's purpose and a strong, enabled TDES wrapping key with wrap or unwrap permission. |
| A KEK validation request uses a non-TDES key, lacks the needed mode, names an invalid form, or carries a non-block-sized random value | The validation request returns ValidationException. | Use a TDES key-encryption key with the required mode and one supported validation form and length. |
| A DUKPT KSN is not valid or has a zero transaction counter | Transaction key derivation fails. | Send a hexadecimal KSN of the supported length with a non-zero counter. |
| DUKPT is used with an AES PIN-block format | The PIN operation is refused because DUKPT produces a TDES working key. | Use DUKPT only with a TDES PIN-block format. |
| A PIN block uses the wrong account number, key family, or format | The block is invalid or PIN verification fails. | Use the same account number and a PIN key that matches the block format. |
| A payment value does not match the supplied inputs | Verification returns VerificationFailedException. | Use the same key, account data, transaction data, and variant as the producer. |
| A certificate subject uses a non-ASCII email value | Certificate request validation fails. | Use ASCII for the email subject member. |
| An alias moves while a request is running | A request could use a different key after authorization if resolution is not pinned. | Preserve request-scoped alias resolution. |
Key files
| File | Why to read it |
|---|---|
| src/…/PaymentCryptographyJsonHandler.java | Shows the control-plane actions, request mapping, response shape, and key-material form selection. |
| src/…/PaymentCryptographyService.java | Defines regional key and alias state, deletion, tags, lookup, and import or export boundaries. |
| src/…/PaymentCryptographyRequestShapes.java | Defines control-plane request validation. |
| src/…/PaymentCryptographyDataRequestShapes.java | Defines data-plane request validation. |
| src/…/PaymentCryptographyMembers.java | Shows the shared conversion from JSON members to service input values. |
| src/…/PaymentCryptographyKeyExchange.java | Shows the supported import, export, certificate, token, RSA, ECDH, TR-34, and AS2805 exchange behavior. |
| src/…/PaymentCryptographyCertificateRequest.java | Shows how certificate signing requests represent asymmetric key subjects and signatures. |
| src/…/PaymentCryptographyAs2805Variant.java | Maps AS2805 variants to the payment purpose they bind into a key. |
| src/…/PaymentCryptographyAs2805Cryptogram.java | Shows the authenticated, purpose-bound AS2805 key cryptogram boundary. |
| src/…/PaymentCryptographyKekValidationController.java | Shows the AWS-compatible data-plane route for AS2805 KEK validation. |
| src/…/PaymentCryptographyKekValidationOperations.java | Defines the KEK validation request and response forms, key rules, and returned values. |
| src/…/PaymentCryptographyKekValidation.java | Defines AS2805 validation variants, parity handling, inversion, and TDES block work. |
| src/…/PaymentCryptographyCryptoHandler.java | Defines symmetric data protection, MAC selection, key checks, and data-plane response rules. |
| src/…/PaymentCryptographyPinOperations.java | Shows Visa PIN verification, PIN-block generation and translation, format rules, and DUKPT PIN-key behavior. |
| src/…/PaymentCryptographyCardValidationOperations.java | Shows static and dynamic card validation behavior. |
| src/…/PaymentCryptographyAuthCryptogramOperations.java | Shows supported authorization cryptogram derivation and response behavior. |
| src/…/PaymentCryptographyCrypto.java | Defines key check values, symmetric cipher work, and key wrapping primitives. |
| src/…/BlockMode.java | Defines the symmetric mode names and their IV and feedback rules. |
| src/…/Cfb1.java | Defines the single-bit feedback mode used by the symmetric data plane. |
| src/…/DukptCrypto.java | Defines DUKPT transaction-key and working-key derivation. |
| src/…/EmvCrypto.java | Defines EMV key derivation and authorization cryptogram calculations. |
| src/…/Tr34.java | Defines the signed and enveloped TR-34 key exchange boundary. |
| src/…/RsaOaep.java | Defines RSA-OAEP wrapping and unwrapping rules. |
| src/…/Ecdh.java | Defines the shared-secret step for asymmetric key exchange. |
| src/…/ConcatKdf.java | Defines the supported shared-secret key derivation forms. |
| src/…/Certificates.java | Defines accepted certificate encodings and certificate parsing. |