HSM KitHSM Kit
Deutsch

TR-31 Key Block Format Explained

Schlüsselverwaltung# TR-31# Schlüsselblock# ANSI X9.143# HSM
Zuletzt aktualisiert: January 16, 20263 Min. LesezeitBy HSM Kit Team
Müssen Sie jetzt berechnen?
Nutzen Sie unser kostenloses Online-TR-31 Key Block Tool-Werkzeug.

TR-31 (also known as ANSI X9.143) is the industry standard format for securely wrapping and transporting cryptographic keys. This guide provides a comprehensive overview of the format.

What is TR-31?

TR-31 is a key block specification that provides:

  • Key encryption: Protects the key during transport
  • Key binding: Ties key attributes to the key material
  • Integrity protection: Detects tampering
  • Key usage control: Defines how the key can be used

Key Block Structure

A TR-31 key block consists of several parts:

[Version][Block Length][Key Usage][Algorithm][Mode][Key Version][Exportability][Optional Blocks][Key Data][MAC]

Header Fields

FieldLengthDescription
Version ID1'A' (TDES), 'B' (TDES-KD), 'C' (TDES-V), 'D' (AES)
Block Length4Total block length in bytes (hex)
Key Usage2Purpose of the key (P0, K0, B0, etc.)
Algorithm1Key algorithm (T=TDES, A=AES)
Mode of Use1How key can be used (E=Encrypt only, etc.)
Key Version2Version number
Exportability1Export restrictions (E, N, S)
Opt. Blocks2Number of optional blocks

Key Usage Codes

Common key usage codes:

CodeDescription
P0PIN Encryption Key
B0BDK Base Derivation Key
K0Key Encryption/Wrapping Key
M0ISO 9797-1 MAC (Algorithm 1)
M3ISO 9797-1 MAC (Algorithm 3)
D0Symmetric Key for Data Encryption
V0PIN Verification Key (VISA PVV)

Mode of Use

CodeDescription
BBoth encrypt and decrypt
CCompute (MAC generation only)
DDecrypt only
EEncrypt only
GGenerate keys
NNo special restrictions
SSignature only
VVerify (MAC verification only)
XKey derivation

Exportability

CodeDescription
EExportable (in trusted key block)
NNon-exportable
SSensitive (exportable only to non-exportable)

Version Differences

Version A (Original TDES)

  • Uses TDES key wrapping
  • 16-byte MAC
  • Basic security

Version B (TDES Key Derivation)

  • Uses key derivation before wrapping
  • Improved cryptographic binding
  • 16-byte MAC

Version C (TDES Variant)

  • Uses CMAC instead of X9.19 MAC
  • Better integrity protection

Version D (AES)

  • Uses AES for key wrapping (AES-256 KBPK)
  • CMAC for authentication
  • Strongest security
  • Recommended for new implementations

Encoding Example

Let's encode a PIN encryption key (P0):

Inputs:

  • Key: 0123456789ABCDEFFEDCBA9876543210
  • KBPK: 00112233445566778899AABBCCDDEEFF
  • Usage: P0 (PIN Encryption)
  • Algorithm: T (TDES)
  • Mode: B (Both directions)
  • Exportability: E

Result:

D0112P0TB00E0000...

Decoding a Key Block

When you receive a TR-31 key block:

  1. Verify header: Check version, usage, algorithm
  2. Verify MAC: Using your KBPK
  3. Decrypt key: Using the derived encryption key
  4. Apply key: According to usage and mode

Security Best Practices

  1. Use Version D: AES-based protection is strongest
  2. Strong KBPK: Use 256-bit AES KBPKs
  3. Verify before use: Always verify MAC before decryption
  4. Honor restrictions: Respect exportability and mode flags
  5. Key rotation: Regularly rotate KBPKs

Common Issues

"MAC verification failed"

  • KBPK mismatch
  • Corrupted key block
  • Wrong version decoding

"Invalid key length"

  • Algorithm mismatch
  • Padding issues

"Unknown key usage"

  • Unsupported or vendor-specific code

Try It Yourself

Use our TR-31 Key Block Tool to:

  • Encode keys into TR-31 format
  • Decode and verify existing key blocks
  • View all header fields and attributes
  • Support for all versions (A, B, C, D)

All processing happens locally in your browser for maximum security.

Verwandtes Werkzeug
TR-31 Key Block Tool