Ambimat GroupAmbimatAmbiSecureSIMAuthAmbiAutomationEngineering BlogAhmedabad · India · Est. 1981
Smart card utility

APDU Builder

Assemble a valid ISO/IEC 7816-4 command APDU from CLA, INS, P1, P2, optional command data and Le. The tool detects the case, computes Lc, and picks short or extended length for you — or paste an APDU back in to break it into fields.

Client-sideISO 7816-4Short & extended

Command fields

Command APDU

Fill in the header to build a command APDU.

Parse an APDU back

Decoded fields

Paste an APDU hex to break it into fields.
All assembly and parsing runs locally in your browser. Nothing is uploaded — safe for commands containing keys or PINs.

What this builder does

A command APDU (Application Protocol Data Unit) is the packet a host sends to a smart card or secure element under ISO/IEC 7816-4. Every command starts with a four-byte header — CLA (class), INS (instruction), and the two parameters P1 and P2 — and may optionally carry a command body and a request for response data. This tool takes those pieces, validates each one, and emits the exact byte sequence a reader will transmit over the contact or contactless interface. It is the inverse of the APDU parser: instead of decoding bytes into meaning, it composes meaning into bytes.

Crucially, the builder does not let you type a length field by hand. Lc is the length of the command data, so it is derived from the Data field automatically, and the tool chooses short or extended encoding based on the sizes involved. That removes the single most common source of a 6700 "wrong length" rejection.

When to use it

Reach for the builder when you are scripting a card personalisation flow, writing a test vector for a JavaCard applet, debugging a reader integration, or simply learning how the four cases differ. It is handy for hand-crafting a SELECT by AID before a transaction, a GET RESPONSE to retrieve buffered bytes after a 61xx status, or a VERIFY command while testing PIN handling. The example dropdown seeds realistic headers you can then tweak. Pair it with the CLA byte decoder when you are unsure which class byte to use, and the status word dictionary to interpret the card's reply.

Inputs and outputs

Each header field (CLA, INS, P1, P2) accepts exactly one byte written as two hex digits; spaces and a 0x prefix are tolerated and stripped. The Data field accepts any number of whole hex bytes and may be left empty. The Le control offers three choices: no Le at all, the maximum (a short 00 meaning 256, or extended 00 00 meaning 65536), or an exact decimal byte count. From those inputs the tool reports the detected case, the total byte length, the computed Lc, and whether extended length was triggered, then prints the full APDU as space-separated hex you can copy straight into a reader script.

Short vs extended length

Short length

One byte for Lc (1–255) and one byte for Le (1–256, with 00 meaning 256). The default for almost all everyday commands.

Extended length

Three bytes — a leading 00 then a big-endian 16-bit value — used when data exceeds 255 bytes or you expect more than 256 back. The card must support it.

Case detection

Case 1 is header only; Case 2 adds Le; Case 3 adds data; Case 4 carries both. The builder picks the case from the fields you fill.

Common mistakes

Related tools

APDU parser

Decode a command or response APDU into named fields and status words.

Open APDU parser →

CLA byte decoder

Break the class byte into channel, secure-messaging, and chaining bits.

Open CLA decoder →

Status word dictionary

Look up the meaning of the SW1 SW2 the card returns.

Open status dictionary →