HSM Simulator

Emulate a Thales PayShield 10K Hardware Security Module for payment application development. Full support for key management, PIN operations, encryption, MAC generation, and more.

Overview

The HSM Simulator in ISO8583Studio emulates a Thales PayShield 10K Hardware Security Module. It allows you to develop and test payment host applications that require HSM integration without needing access to physical HSM hardware.

🔐

Key Management

Generate, import, export, and translate cryptographic keys including ZMK, ZPK, TPK, BDK, ZEK, and more.

🔢

PIN Operations

Translate PIN blocks between keys, verify PINs using IBM 3624 and VISA PVV methods, and generate PIN offsets.

🔒

Encryption / Decryption

Encrypt and decrypt data blocks with DES/3DES in ECB and CBC modes using ZEK, DEK, or BDK keys.

📝

MAC Generation

Generate and verify MACs using ISO 9797 Algorithm 1 and Algorithm 3 with ZAK or TAK keys.

🔑

RSA Support

Generate RSA key pairs, import public keys, and create/validate digital signatures.

💾

LMK Storage

Multiple LMK slots, persistent key storage, and full LMK lifecycle management.

Quick Start Guide

  1. Create an HSM configuration — From the Home screen, create a new HSM Simulator configuration. Set the profile name and device details.
  2. Configure network settings — Set the TCP/IP bind address and port (e.g. 0.0.0.0:9090). Configure the message header length (default: 4 characters).
  3. Launch the simulator — Open the HSM Simulator screen and start the server from the HSM Handler tab.
  4. Connect your application — Point your host application to host:port and send PayShield host commands.
  5. Test with built-in commands — Use the Host Commands tab to send commands interactively and inspect responses.
Tip

Start with the NC (Diagnostic Test) command to verify the simulator is running and LMK is loaded. A response of ND00 confirms everything is healthy.

Message Protocol

The HSM Simulator uses the standard Thales PayShield host command protocol over TCP/IP.

Request Format

[Length Header (2 bytes, optional)][Message Header (4 chars)][Command Code (2 chars)][Data Fields][%LMK_ID][Trailer]
ComponentSizeDescription
Length Header2 bytesOptional. Big-endian message length (excluding the length header itself).
Message Header4 charsConfigurable header echoed back in response (e.g. 0000).
Command Code2 charsTwo-character command identifier (e.g. NC, A0).
Data FieldsVariableCommand-specific data parameters.
LMK ID3 charsOptional %XX suffix to select a specific LMK slot.
TrailerVariableOptional end-of-message marker (\u0019 + trailer data).

Response Format

[Length Header (2 bytes, optional)][Message Header][Response Code][Error Code (2 chars)][Response Data]

The response code is the command code incremented by one character (e.g. NCND, A0A1). An error code of 00 indicates success.

Example Exchange

Request:  0000NC
Response: 0000ND00LMK12345678901234567890123456789012345678

Request:  0000A0001U
Response: 0000A100U1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF

Encoding

All messages use ISO-8859-1 encoding. Keys are represented as hexadecimal strings in the protocol.

Network Settings

TCP/IP Configuration

SettingDefaultDescription
Bind Address0.0.0.0IP address to listen on. Use 0.0.0.0 for all interfaces.
Port9090TCP port for the HSM server.
Length HeaderOptionalEnable 2-byte big-endian length prefix before each message.
Message Header Length4Number of characters in the message header (echoed back in response).

Additional Connection Types

  • Serial — RS232 connection with configurable port, baud rate, data bits, stop bits, and parity.
  • REST API — HTTP endpoint for HSM commands.
  • WebSocket — Real-time bidirectional HSM communication.

LMK Storage

The Local Master Key (LMK) is the foundation of HSM security. All working keys are encrypted under LMK pairs.

LMK Structure

  • 40 LMK Pairs — Pairs 00–39, each consisting of a left key and right key. Different key types are encrypted under specific LMK pairs.
  • Multiple LMK Slots — Slots 00–99 allow independent LMK sets. Select the slot using %XX in commands or via port mapping.
  • Old / New LMK — Support for LMK migration with the BW (Translate Key) command.

LMK Pair Assignments

LMK PairKey Type Encrypted
Pair 02–03PIN Encryption Keys (PINs under LMK)
Pair 04–05ZMK (Zone Master Keys)
Pair 06–07ZPK, TPK (Zone/Terminal PIN Keys)
Pair 14–15PVK (PIN Verification Keys)
Pair 16–17TAK (Terminal Authentication Keys)
Pair 22–23BDK (Base Derivation Keys)
Pair 26–27ZEK, DEK (Data Encryption Keys)
Pair 28–29ZAK (Zone Authentication Keys)

Persistence

LMK data is stored in payShield10k_lmkStorage.json and within the simulator configuration JSON. Keys persist across restarts.

Diagnostics & Info Commands

CommandResponseNameDescription
NCNDDiagnostic TestHealth check. Returns 00 if the HSM and LMK are functioning correctly.
NONPReservedReserved diagnostic command.
VRVSVersion InfoReturns firmware version and serial number of the emulated HSM.
VTVUView LMK TableDisplays Key Check Values (KCVs) of all 40 loaded LMK pairs.
GKGLGenerate LMK ComponentGenerates a random LMK component for key loading ceremonies.

Example: Diagnostic Test

Request:  0000NC
Response: 0000ND00

Error code 00 = HSM is healthy, LMK loaded.

Key Management Commands

CommandResponseNameDescription
A0A1Generate KeyGenerates a new DES/3DES key encrypted under LMK. Optionally also encrypted under a ZMK for transport.
A6A7Import KeyImports a key encrypted under ZMK and re-encrypts it under LMK.
A8A9Export KeyExports a key from LMK encryption to ZMK encryption for transport to another zone.
BUBVGenerate KCVGenerates a Key Check Value (KCV) for a given key. Used to verify key integrity.
BWBXTranslate Key (LMK)Translates a key from old LMK encryption to new LMK encryption during LMK migration.
GCGDGenerate ComponentsGenerates N random key components. Used in split-knowledge key ceremonies.
FKFLForm Key from ComponentsXORs 2 or 3 key components together to form a working key under LMK.

Example: Generate a ZPK

Request:  0000A0001U
                ^^^ ^^^
                |   |-- Key scheme: U = double-length
                |------ Key type: 001 = ZPK

Response: 0000A100U<key-under-LMK><key-under-ZMK><KCV>

Example: Generate KCV

Request:  0000BU0U<key-under-LMK>
Response: 0000BV00<6-char-KCV>

PIN Block Operations

CommandResponseNameDescription
BABBEncrypt PIN BlockEncrypts a clear-text PIN into a PIN block under TPK or ZPK.
CACBTranslate PIN (TPK → ZPK)Re-encrypts a PIN block from Terminal PIN Key to Zone PIN Key.
CICJTranslate PIN (ZPK → TPK)Re-encrypts a PIN block from Zone PIN Key to Terminal PIN Key.
BCBDTranslate PIN BlockTranslates PIN block between encryption keys.
G0G1Translate PIN (DUKPT → ZPK)Translates a DUKPT-encrypted PIN block to ZPK encryption.
JCJDTranslate PIN (TPK → LMK)Re-encrypts a TPK-encrypted PIN block under LMK.
JEJFTranslate PIN (ZPK → LMK)Re-encrypts a ZPK-encrypted PIN block under LMK.
JGJHTranslate PIN (LMK → ZPK)Re-encrypts an LMK-encrypted PIN to a ZPK PIN block.
NGNHGenerate DUKPT KeyDerives a DUKPT session key from a BDK and Key Serial Number.

Example: Translate PIN (TPK → ZPK)

Request:  0000CA<TPK><ZPK><max-pin-length><pin-block>01<account-number>01<account-number>
Response: 0000CB00<pin-length><translated-pin-block>
Note

The CA command is the most commonly used PIN translation in payment processing. It converts a PIN block received from the terminal (encrypted under TPK) into a block suitable for sending to the card issuer (encrypted under ZPK).

PIN Verification Commands

CommandResponseNameDescription
DADBVerify PIN (IBM 3624)Verifies a PIN using the IBM 3624 natural PIN method with offset data.
DCDDVerify PIN (VISA PVV)Verifies a PIN against a VISA Pin Verification Value (PVV).

Example: VISA PVV Verification

Request:  0000DC<ZPK>01<pin-block><account-number><PVK-pair><PVV>
Response: 0000DD00   (00 = PIN verified successfully)
Response: 0000DD01   (01 = PIN verification failed)

PIN Generation Commands

CommandResponseNameDescription
DEDFGenerate IBM PIN OffsetGenerates an IBM 3624 PIN offset. Used for PIN issuance.
DGDHGenerate VISA PVVGenerates a VISA Pin Verification Value for a given PIN.
EEEFDerive PIN from OffsetDerives the natural PIN from an IBM 3624 offset and validation data.

Data Encryption / Decryption Commands

CommandResponseNameDescription
M0M1Encrypt Data BlockEncrypts a data block using ZEK, DEK, or BDK in ECB or CBC mode.
M2M3Decrypt Data BlockDecrypts a data block using ZEK, DEK, or BDK.
M4M5Translate Data BlockRe-encrypts data from one key to another (e.g. DUKPT to ZEK).

Cipher Modes

  • ECB (Electronic Codebook) — Each block encrypted independently. Simpler but less secure for repetitive data.
  • CBC (Cipher Block Chaining) — Each block XORed with the previous ciphertext block. Requires an IV (Initialization Vector).

MAC Operations

CommandResponseNameDescription
M6M7Generate MACGenerates a MAC using ZAK or TAK with ISO 9797 Algorithm 1 or 3.
M8M9Verify MACVerifies a MAC value against the original data and key.
MYMZMAC VariantsAdditional MAC algorithm and format variants.

MAC Algorithms

  • ISO 9797 Algorithm 1 — Single DES CBC-MAC. Standard for most payment applications.
  • ISO 9797 Algorithm 3 — Retail MAC (DES CBC-MAC with final 3DES step). Provides stronger security.

Hashing Commands

CommandResponseNameDescription
GMGNHash DataComputes a hash digest of the input data.

Supported Algorithms

  • SHA-1
  • SHA-256
  • MD5

RSA / Asymmetric Commands

CommandResponseNameDescription
EIEJGenerate RSA Key PairGenerates an RSA public/private key pair. Private key encrypted under LMK.
EOEPImport RSA Public KeyImports a DER-encoded RSA public key into the HSM.
EWEXGenerate SignatureCreates an RSA or ECDSA digital signature over input data.
EYEZValidate SignatureValidates an RSA or ECDSA signature against the original data.

Dynamic CVV/CVC

CommandResponseNameDescription
PMPNVerify Dynamic CVV/CVCVerifies Visa dCVV or MasterCard CVC3 values for contactless transactions.

User Storage Commands

Store, retrieve, and delete keys or data in indexed user storage slots (000–FFF).

CommandResponseNameDescription
LALBLoad to StorageStores a key or data at a specified storage index (000–FFF).
LELFRead from StorageRetrieves data from a specified storage index.
LDLMDelete from StorageDeletes the entry at a specified storage index.

Key Types & Schemes

Key Types

CodeNamePurpose
000ZMKZone Master Key — Key-encrypting key for secure key exchange between zones.
001ZPKZone PIN Key — Encrypts PIN blocks for transmission between zones.
002TPK / PVKTerminal PIN Key / PIN Verification Key — Terminal PIN encryption or PIN verification.
003TAKTerminal Authentication Key — MAC generation at the terminal.
008ZAKZone Authentication Key — MAC generation between zones.
009BDKBase Derivation Key — Master key for DUKPT key derivation.
00AZEKZone Encryption Key — Data encryption between zones.
00BDEKData Encryption Key — General-purpose data encryption.
302IKEYIntermediate Key — Internal processing key.

Key Schemes

SchemeHex LengthDescription
X16 charactersSingle-length DES key (56 effective bits).
U32 charactersDouble-length 3DES key (112 effective bits). Most common for payment.
T48 charactersTriple-length 3DES key (168 effective bits). Maximum DES security.

PIN Block Formats

CodeFormatDescription
01ISO 9564-1 Format 0Standard ISO format. PIN XORed with PAN. Most widely used.
02ISO 9564-1 Format 1ISO format without PAN dependency.
03DocutelLegacy Docutel ATM format.
04PLUSPLUS network PIN block format.
05ISO 9564-1 Format 3ISO format with random fill.
06DieboldLegacy Diebold ATM format.
47ISO 9564-1 Format 4AES-based PIN block format (newer, more secure).
46AS2805Australian standard PIN block format.

Error Codes

Every HSM response includes a 2-character error code. 00 indicates success.

CodeMeaning
00No error — command executed successfully.
01Verification failure (PIN or MAC mismatch).
02Key Check Value (KCV) failure.
04Cryptographic algorithm not supported.
10PIN block length error.
15Invalid input data.
17Invalid message length.
23PIN length error.
26Invalid LMK identifier.
27LMK check value failure.
39Console authorization required.
42Invalid LMK type code.
68Command is disabled.
74Data parity error in key or data block.
75Invalid message length field.
80Unknown command or invalid format.
82Function not permitted by current configuration.
A1Console not authorized. Grant authorization first.
A2HSM not authorized.
A3Command only available in secure state.
A4Invalid key type for this command.
B1Invalid key scheme code.
C1LMK is not loaded. Load LMK before issuing commands.

UI Tabs Reference

TabDescription
HSM HandlerStart/stop the HSM server. View live request/response traffic, connection count, and server status.
Key ManagementView loaded LMK status, key check values, and manage key components.
Host CommandsInteractive command forms for all ~35 supported commands. Grouped by category with search and filtering. Shows wire-format hints and formatted results.
Secure CommandsAdministrative and LMK-related operations requiring console authorization (GC, FK, GK, A0, etc.).
LogsFull request/response log of all HSM traffic.

Secure Commands

Certain operations require console authorization before they can be executed, simulating the real PayShield security model.

Authorization Flow

  1. Grant Authorization — In the Secure Commands tab, click the authorization button. This simulates inserting a custodian smart card.
  2. Execute Commands — While authorized, you can run secure commands like GC, FK, GK, and LMK management operations.
  3. Authorization Timeout — Authorization expires after a configurable period (default: 8 hours) or when manually revoked.

Secure Command List

The following commands are available in the Secure Commands tab:

CommandNamePurpose
NCDiagnostic TestVerify HSM health.
VRVersion InfoCheck firmware version.
VTView LMK TableDisplay all LMK KCVs.
GKGenerate LMK ComponentCreate LMK key component.
GCGenerate Key ComponentsGenerate N random components for split knowledge.
FKForm Key from ComponentsXOR components to form a key.
A0Generate KeyGenerate working keys under LMK.
LALoad to StorageStore data in HSM user storage.
LERead from StorageRetrieve from user storage.
LDDelete from StorageRemove user storage entry.
BWTranslate KeyLMK migration — old to new LMK.
DEGenerate IBM PIN OffsetPIN issuance with IBM 3624.
DGGenerate VISA PVVPIN issuance with VISA PVV.
EIGenerate RSA Key PairAsymmetric key generation.
Important

Attempting to run a secure command without authorization will return error code A1 (Console not authorized). Always grant authorization before executing these operations.