DUKPT Tools

Derived Unique Key Per Transaction (DUKPT) is the standard mechanism for protecting card data and PINs at the point of sale. ISO8583Studio includes calculators for both DUKPT AES (ANSI X9.24-3) and DUKPT ISO 9797 / 3DES (ANSI X9.24-1).

What is DUKPT?

DUKPT generates a unique cryptographic key for every transaction without ever transmitting that key. The terminal stores a single Initial PIN Encryption Key (IPEK) derived from a Base Derivation Key (BDK) and a Key Serial Number (KSN). For each transaction the terminal advances the KSN counter and derives a fresh transaction key. The host, knowing only the BDK and the KSN it received, derives the same transaction key independently.

Why use DUKPT?

If a terminal is compromised, only future transaction keys can be derived (forward secrecy is built in). Past transactions remain protected because the terminal never stored the keys it used.

DUKPT Variants

VariantStandardCipherBDK LengthKSN Length
DUKPT ISO 9797ANSI X9.24-13DES16 bytes (32 hex)10 bytes (20 hex)
DUKPT AESANSI X9.24-3AES-128 / 192 / 25616 / 24 / 32 bytes12 bytes (24 hex)

If you’re working with legacy 3DES terminals, use the ISO 9797 variant. New deployments should use AES DUKPT.

Key Concepts

  • BDK (Base Derivation Key) — A master key shared between terminal manufacturer / acquirer and the host. Never used directly to encrypt data.
  • KSN (Key Serial Number) — A unique identifier for a terminal + transaction counter. Increments with every transaction.
  • IPEK (Initial PIN Encryption Key) — First key loaded into a terminal, derived from BDK + KSN.
  • Transaction Key — The key actually used for a single transaction; derived from the IPEK and the current KSN counter.
  • Working Keys — Purpose-bound keys (PIN, MAC, Data) derived by applying variant XOR masks to the transaction key.

DUKPT ISO 9797 (3DES) Tool

The DUKPT ISO 9797 calculator implements ANSI X9.24-1 with 3DES. It is split across five tabs — two derivation tabs that produce working keys, and three operation tabs that consume those keys.

Tabs (5)

  • PEK Derivation — Derive a PIN Encryption Key from BDK or IPEK + KSN.
  • DEK Derivation — Derive a Data Encryption Key from BDK or IPEK + KSN.
  • DUKPT PIN — Encrypt or decrypt a PIN block with a previously derived PEK.
  • DUKPT MAC — Generate a MAC over hex data with a previously derived PEK / MAC key.
  • DUKPT Data — Encrypt or decrypt arbitrary data with a previously derived key.
Two-step workflow

The tool deliberately separates derivation from use: derive the working key in PEK Derivation or DEK Derivation first, then paste the result into the DUKPT PIN / MAC / Data tab. This mirrors how a host-side stack stages keys.

PEK Derivation Tab

Inputs

  • Input Key Designation — Radio / toggle: BDK or IPEK. Determines which key field is shown.
  • BDK (32 Hex Chars) — Visible when input is BDK.
  • IPEK (32 Hex Chars) — Visible when input is IPEK.
  • KSN (20 Hex Chars) — Always visible.

Button: Derive PEK.

Walk-through

  1. Pick Input Key DesignationBDK if you have the base key; IPEK if a previous step already produced the initial key.
  2. Enter the key in the resulting BDK or IPEK field (32 hex chars).
  3. Enter KSN — 20 hex chars (rightmost 21 bits are the transaction counter).
  4. Click Derive PEK — The activity log shows the resulting PIN Encryption Key. Copy it for the operation tabs.

DEK Derivation Tab

Identical fields and flow to PEK Derivation — the only difference is the variant applied to produce a Data Encryption Key.

Inputs

  • Input Key DesignationBDK or IPEK.
  • BDK (32 Hex Chars) / IPEK (32 Hex Chars).
  • KSN (20 Hex Chars).

Button: Derive DEK.

DUKPT PIN Tab

Encrypt or decrypt a PIN block using a working key you derived in PEK Derivation.

Inputs

  • PEK (32 Hex Chars) — Paste the PEK from the PEK Derivation tab.
  • PIN Block (16 Hex Chars) — Clear (encrypt) or encrypted (decrypt) PIN block.

Buttons: Encrypt, Decrypt.

DUKPT MAC Tab

Compute a MAC over hex data with a previously derived working key.

Inputs

  • PEK (32 Hex Chars) — The MAC key (typically derived in the PEK Derivation tab).
  • Algorithm — Radio: DES or 3DES.
  • Data (Hex) — Multi-line hex input.

Button: Generate MAC.

DUKPT Data Tab

Encrypt or decrypt sensitive data fields (track 2, EMV data) with a derived key.

Inputs

  • PEK (32 Hex Chars) — Working key from PEK Derivation (or DEK Derivation when the data variant key is required).
  • Use Data Variant Key — Switch. When on, the tool applies the data-encryption variant XOR before encrypting.
  • Data Input TypeASCII or Hex.
  • Cipher Mode — Radio: CBC or ECB.
  • Data — Multi-line input matching the chosen format.

Buttons: Encrypt, Decrypt.

DUKPT AES Tool

Implements ANSI X9.24-3 with AES. Four tabs split derivation from operations.

Tabs (4)

  • Key Derivation — Derive a working key from BDK or IK + KSN.
  • DUKPT PIN — PIN block encrypt / decrypt.
  • DUKPT MAC — MAC generation.
  • DUKPT Data — Data encrypt / decrypt.

Key Derivation Tab

Inputs

  • Input Key Designation — Radio / toggle: BDK or IK.
  • Initial Key Type — Drop-down: AES-128, AES-192, AES-256.
  • BDK / IK — Hex; length matches the initial key type.
  • Working Key Type — Drop-down: 2TDEA, 3TDEA, AES-128, AES-192, AES-256.
  • KSN — 24 hex chars (12 bytes: 4-byte BDK ID + 4-byte derivation ID + 4-byte counter).

Button: Derive Keys.

Walk-through

  1. Pick Input Key DesignationBDK or IK.
  2. Pick Initial Key Type — AES-128 / 192 / 256.
  3. Enter the BDK / IK.
  4. Pick Working Key Type — The tool can derive both AES and TDES working keys for backwards compatibility.
  5. Enter KSN.
  6. Click Derive Keys — The activity log lists the IK (when starting from BDK) and the working key.
Counter Field

The 32-bit counter only uses values with at most 16 set bits to allow efficient forward derivation. The tool flags invalid counters.

DUKPT PIN Tab (AES)

Inputs

  • PEK (Pin Encryption Key) — Hex working key from Key Derivation.
  • PIN Block — Hex.

Buttons: Encrypt, Decrypt.

DUKPT MAC Tab (AES)

Inputs

  • MAC Generation Key — Hex working key from Key Derivation.
  • Data (Hex) — Multi-line input.

Button: Generate MAC.

DUKPT Data Tab (AES)

Inputs

  • DEK (Data Encryption Key) — Hex working key from Key Derivation.
  • Data Input TypeASCII or Hex.
  • Data — Multi-line input.

Buttons: Encrypt, Decrypt.

KSN Structure

3DES KSN (10 bytes)

| 5-byte BDK ID + Device ID  |   2-byte counter (high)   | 21-bit Tx Counter |
|--------------------------- |---------------------------|-------------------|
|         59 bits            |          remaining         |     21 bits        |

AES KSN (12 bytes)

| 4-byte BDK ID | 4-byte Derivation ID | 4-byte Transaction Counter |

Increment the counter by one for every transaction. After exhausting the counter space, the device must be re-keyed.

Tips & Pitfalls

  • The KSN you receive in field 53 / 60 of an ISO 8583 message is what the host uses to derive the same key. Keep them in sync — off-by-one is the most common bug.
  • For PIN translation tests, capture the PIN block at the same instant as the KSN. Re-using a KSN with a different PIN block will fail.
  • If you suddenly start getting wrong MACs, check whether your terminal advanced the counter without you advancing yours. Use the increment button to re-sync.
  • Keep BDKs out of source control. The activity log persists keys in memory during the session but never writes them to disk.