All Tools
Tools/TR-31 Key Block
🗝️
CryptographyAvailable

TR-31 Key Block

Interoperable Secure Key Exchange — parse TR-31 key blocks, explore the header structure, and understand real-world use cases for secure key distribution between HSMs.

Use test data only. All calculations run locally in your browser — PayProbe never sees, transmits, or stores your PAN, CVV, keys, PINs, or cryptographic inputs. How we handle data →

What is TR-31?

TR-31 (ANS X9.143) defines a standard format for wrapping cryptographic keys when exchanging them between secure modules (HSMs, PEDs, ATMs). The standard ensures that a key's intended usage, algorithm, and exportability are cryptographically bound to the key value — preventing mis-use or substitution attacks.

A TR-31 key block is an opaque ASCII string that contains a 16-character header, optional extension blocks, the encrypted key value, and an authentication MAC — all protected by a Key Block Protection Key (KBPK).

Why TR-31 matters

  • 🔒Attribute binding — usage and algorithm are authenticated, not just encrypted
  • 🚫Prevents key substitution — a PIN key cannot be re-used as a MAC key
  • 🔄Interoperability — Thales, Futurex, Utimaco, nCipher all support the same block format
  • 📋PCI HSM compliance — TR-31 is the PCI-mandated format for key exchange between HSMs
  • 🏧Required for DUKPT, ZPK, and EMV key distribution in modern payment deployments

Key Block Structure

A TR-31 block is an ASCII string. Each coloured segment maps to a header field.

1cVersion ID
4cBlock Length
2cKey Usage
1cAlgorithm
1cMode of Use
2cKey Version
1cExport- ability
2cOpt Blocks
2cReserved
variableOptional Blocks
variableEncrypted Key
16 / 32cMAC
Version IDBinding method: A/B (DES variant), D (AES CMAC)
Block LengthTotal characters in the key block (header + payload + MAC)
Key UsagePurpose of the key: P0 PIN, K0 KEK, B0 BDK …
AlgorithmCryptographic algorithm: A AES, T 3DES, R RSA …
Mode of UseAllowed operations: E encrypt, D decrypt, B both …
Key VersionKey version number; 00 = not used
Export- abilityE exportable, N non-exportable, S sensitive
Opt BlocksCount of optional blocks that follow the fixed header
ReservedMust be "00"; reserved for future use

Version Identifiers

A

Version A

DES, variant key binding

Deprecated
B

Version B

2TDEA (double-length), variant key binding

C

Version C

3TDEA, variant key binding

Deprecated
D

Version D

AES-128/192/256, CMAC key binding