TR-31 key block decoder and builder
Decode a TR-31 / X9.143 key block header; unwrap or build one with a test KBPK.
- Runs in your browser
- No sign-up
Input
MAC verified, key unwrapped.
Result
- Key length
- 128 bits (16 bytes)
- KCV
- 57C409
| Field | Value | Meaning |
|---|---|---|
| Versionchars 1 | B | TDES key derivation binding |
| Key block lengthchars 2–5 | 0080 | 80 characters |
| Key usagechars 6–7 | P0 | PIN encryption key |
| Algorithmchars 8 | T | Triple DES |
| Mode of usechars 9 | E | Encrypt / wrap only |
| Key version numberchars 10–11 | 00 | Not used |
| Exportabilitychars 12 | E | Exportable under a trusted key (X9.24 key block) |
| Optional blockschars 13–14 | 00 | 0 optional blocks |
| Reserved / key contextchars 15–16 | 00 | Not used |
Steps
Test keys only: never paste a production KBPK or key into a web page.
Exchanging keys under TR-31 with a processor or HSM? IDNTEQ coordinates key hand-offs. Card-program implementation in Brazil
About this tool
Runs in your browser. This page loads no analytics or third-party scripts and does not send what you type.
Paste a key block to read each header field and optional block with its meaning. Add the test KBPK to verify the MAC and get the clear key with its KCV, or switch to Build to wrap a key.
Versions
Versions B (TDES) and D (AES) derive an encryption key and a MAC key from the KBPK with CMAC. The MAC covers the header and the clear key data, and is also the IV that encrypts the key data. Versions A and C derive the two keys by XOR with 45 and 4D bytes and use a 4-byte CBC-MAC; A is deprecated. Version E (ISO 20038) headers are read but not unwrapped.
Worked example
TR-31:2018 example A.7.2.2: KBPK DD7515F2BFC17F85CE48F3CA25CB21F6 and the block B0080P0TE00E0000… unwrap to the PIN key 3F419E1CB7079442AA37474C2EFBF8B8, KCV 57C409. The header reads: version B, 80 characters, usage P0 (PIN encryption), algorithm T (TDES), mode E (encrypt only), no key version, exportable under a trusted key, no optional blocks.
Building a block
The clear key data is a 2-byte key length in bits, the key and padding to a whole number of cipher blocks. Padding is random unless entered; enter the padding of a published block to rebuild it exactly. A PB block is added when the optional blocks do not end on a cipher block boundary.
Spec references
- ASC X9 TR-31:2018 (key block versions A, B, C and D)
- ANSI X9.143:2021 (header fields and optional blocks)
- NIST SP 800-38B (CMAC)
- ANSI X9.24-1:2017 Annex A (key check values)
Verified against
- Specifications
- ASC X9 TR-31:2018 (key block versions A, B, C, D; Annex A.7 examples)
- ANSI X9.143:2021 (header fields, optional blocks)
- NIST SP 800-38B (CMAC)
- Published examples in the tests
- Other checks in the tests
- Each published block is rebuilt byte for byte from its fields, key and padding
- CMAC key derivation against a CMAC built on OpenSSL; wrap and unwrap round trips for every version and KBPK length
- A wrong MAC or KBPK gives no key; malformed headers and lengths are errors
- Inputs
- A key block (versions A–D to unwrap, any version to read the header) and a KBPK in hex; to build, the header fields, optional blocks, key and optional padding.
- Not covered
- Version E (ISO 20038) and TR-34 blocks are not unwrapped. Optional blocks other than KC, KP, HM and BI are shown as text, not checked.
- Last reviewed