For the complete documentation index, see llms.txt. This page is also available as Markdown.

Encryption & Decryption

For EMV ARQC and EMV Batch Data, the device encrypts data using TDES in CBC-like chaining without an Initial Vector:

  • The device begins by TDES encrypting the first 8 bytes of clear text data. The 8-byte result is placed in an encrypted data buffer.

  • Continue using TDES CBC method with the encrypted 8 bytes XORed with the next 8 bytes of clear text; encrypt that result and place it into the encrypted data buffer.

  • Repeat until all clear text bytes have been encrypted.

  • If the final block of clear text contains fewer than 8 bytes, the device pads the end of the block to make 8 bytes.

  • After the final clear text block is XORed with the prior 8 bytes of encrypted data, the device encrypts it and places it in the encrypted data value.

  • No Initial Vector is used.

The host must decrypt the data in 8-byte blocks, ignoring any final unused bytes in the last block. When a value consists of more than one block, use the CBC method to decrypt the data by following these steps:

1

Start with the last block

Start decryption on the last block of 8 bytes (call it block N) using the key.

2

XOR with previous block

XOR the result of the decryption with the next-last block of 8 bytes (block N-1).

3

Repeat backwards

Repeat until reaching the first block.

4

First block handling

Do not XOR the first block with anything.

5

Concatenate blocks

Concatenate all blocks.

6

Truncate padding

Determine the expected length of the decrypted data (for EMV ARQC and EMV Batch Data this information is included as part of the unencrypted data structure) and truncate the end of the decrypted data block to the expected data length, which discards the padding at the end.

How to Determine the Key

When the device and the host are using TDES DUKPT key and the device is encrypting data, the host software must generate a key (the “derived key”) to use for decryption.

1

Determine the Initial Key loaded into the device

The lookup methods the host software uses depend on the overall solution architecture and are outside the scope of this document. Most solutions do this in one of two ways, both of which use the Initial Key Serial Number that arrives with the encrypted data:

  • Look up the value of the Base Derivation Key using the Initial KSN portion of the current KSN as an index value, then use TDES DUKPT algorithms to calculate the value of the Initial Key; or

  • Look up the value of the Initial Key directly, using the Initial KSN portion of the current KSN as an index value.

2

Derive the current key

Apply TDES DUKPT algorithms to the Initial Key value and the encryption counter portion of the KSN that arrives with the encrypted data.

3

Determine key variant used by the device

Determine which variant of the current key the device used to encrypt. The variants are defined in ANS X9.24-1:2009 Annex A. Which variant the host should use depends on the type of data the host is decrypting. The encrypted portions of EMV ARQC and EMV Batch Data both use the Data Encryption, Request or Both Ways variant.

4

Calculate the variant and decrypt

Use the variant algorithm with the current key to calculate that variant, then decrypt the data according to the steps in How to Decrypt Data.

How to Decrypt Data

For EMV ARQC and EMV Batch Data, the device encrypts data using TDES in CBC-like chaining without an Initial Vector:

  • The device begins by TDES encrypting the first 8 bytes of clear text data. The 8-byte result is placed in an encrypted data buffer.

  • Continue using TDES CBC method with the encrypted 8 bytes XORed with the next 8 bytes of clear text; encrypt that result and place it into the encrypted data buffer.

  • Repeat until all clear text bytes have been encrypted.

  • If the final block of clear text contains fewer than 8 bytes, the device pads the end of the block to make 8 bytes.

  • After the final clear text block is XORed with the prior 8 bytes of encrypted data, the device encrypts it and places it in the encrypted data value.

  • No Initial Vector is used.

The host must decrypt the data in 8-byte blocks, ignoring any final unused bytes in the last block. When a value consists of more than one block, use the CBC method to decrypt the data by following these steps:

1

Start with the last block

Start decryption on the last block of 8 bytes (call it block N) using the key.

2

XOR with previous block

XOR the result of the decryption with the next-last block of 8 bytes (block N-1).

3

Repeat backwards

Repeat until reaching the first block.

4

First block handling

Do not XOR the first block with anything.

5

Concatenate blocks

Concatenate all blocks.

6

Truncate padding

Determine the expected length of the decrypted data (for EMV ARQC and EMV Batch Data this information is included as part of the unencrypted data structure) and truncate the end of the decrypted data block to the expected data length, which discards the padding at the end.

Need Help?

For additional support, please contact MagTek Support:

Technical Support:

  • 📧 Email: support@magtek.com

  • 📞 Phone: 1-800-788-6835 (US) | +1-562-546-6616 (International)

  • 🕐 Hours: Monday-Friday, 6:00 AM - 5:00 PM PST

Online Resources:

Documentation Feedback:

Help us improve this documentation! Submit feedback

Last updated