Cryptography tools

Encode/Decode PIN Block

ISO 9564
Calculate, encode/decode and encrypt/decrypt PIN blocks for ISO8583 card payments.

Encode / Decode

pin block

Build an ISO PIN block from PIN + PAN, or decode clear PIN from a block.

ready

Decode — clear PIN

Uses PAN, filler and encoded PIN block above.

Encrypt / Decrypt

3DES / DES

Encrypt an encoded PIN block with DES or Triple DES, or decrypt back.

—

Decrypt

Uses encrypted block and key above.

  How encoding works

ISO-0 PIN block encoding

The most common scenario is ISO-0 PIN Block Encoding. The block calculation begins with setting up the two parts, Block1 and Block2.

PIN block part one is built from character 0, followed by the length of the PIN, then the PIN number, and then fill the value up to 16 characters with F.

Example: 0 + 4 + 1111 + FFFFFFFFFF = 041111FFFFFFFFFF

PIN block part two is built from four zeroes, followed by the card number without the first 3 digits and without the last digit (12 digits).

Example PAN 5516422217375116 → 0000642221737511

Next, HEX XOR the two blocks, then apply 3DES with the PIN encryption key.

  How encryption works

PIN block encryption

To encrypt the PIN block, single DES or Triple DES is applied.

For single DES, a 16-hex (8 byte) key is used.

For Triple DES, a double-length key is used: 32 hex (16 bytes).

block1 = 0 + PIN_LEN + PIN + FFFF...
block2 = 0000 + PAN[3..14]
clear  = XOR(block1, block2)
cipher = 3DES(clear, PEK)
  Related

Recent Articles on Pin