A reader and a smart card talk in short, strict turns: the reader sends one command, and the card sends one response. Every door check, PIN entry and signature is a handful of these exchanges.
Commands and responses
Each message is called an APDU (application protocol data unit), and the format is defined in ISO/IEC 7816-4, the same over contact and contactless interfaces. A command starts with four bytes that say what to do, followed by any data:
| Part | What it says |
|---|---|
| CLA | The class of command, such as standard or secure messaging. |
| INS | The instruction: for example, A4 for SELECT, 20 for VERIFY, 87 for GENERAL AUTHENTICATE. |
| P1, P2 | Parameters for the instruction, such as which key to use. |
| Lc and data | The length of the data that follows, then the data itself: a PIN or a challenge. |
| Le | How many bytes the reader expects back. |
The response is any data the card returns, followed by a two-byte status word. 90 00 means success; other status words carry information, warnings or errors. After a VERIFY with a wrong PIN, 63 C2 means two tries are left (a VERIFY sent without PIN data can also report the tries left). 69 82 means a security condition isn’t met, such as a PIN that hasn’t been verified, and 69 83 means the PIN is blocked. Don’t confuse a status word with the data before it: a successful SELECT returns application information that starts with the tag 61, which is part of the data, not the status.
A typical PIV conversation
- SELECT the application, by its application identifier (AID). A card may hold several applications, and the reader must say which it wants.
- Read what’s needed, such as the certificate for the key the reader will check, using GET DATA.
- VERIFY the PIN, if the operation requires it.
- GENERAL AUTHENTICATE: send a fresh challenge and name the key. The card signs the challenge with its private key, inside the chip. The reader verifies the signature with the public key from the certificate, and verifies the certificate as Module 2 described.
Try it: talk to a simulated PIV card
This simulated card has a PIV application with two keys and allows three wrong PIN tries. Its PIN is 123456. Select the application first, then try the commands in different orders. The signature is real (ECDSA, P-256), made with a key pair generated in your browser. The displayed bytes illustrate the conversation: a physical PIV card formats its response differently, and a relying system also reads and validates the card’s certificate. Nothing is sent or stored.
PIN checks
The card checks the PIN, not the reader or the computer. It keeps a retry counter: each wrong PIN reduces the tries left, a correct one resets it, and when it reaches zero the PIN is blocked. Unblocking needs a separate unblocking code or the issuer’s help, so guessing doesn’t work. A verified PIN stays valid until the card is reset or removed, or another application is selected. A later failed VERIFY also clears it. Selecting the PIV application again while it’s already selected leaves it verified.
The PIN does travel from the keypad to the card, so the reader and its keypad must be trustworthy. On a PIV card, the PIN can be sent over the contactless interface only through the virtual contact interface from lesson 3.3.
Go deeperOptional technical detail for readers who want more
APDUs in detail
In the PIV card command interface, SELECT uses CLA 00, INS A4, P1 04 (select by name) and the PIV AID, A0 00 00 03 08 00 00 10 00 01 00, or its shorter form without the version bytes. VERIFY uses INS 20 with P2 80 for the PIV PIN, padded to eight bytes with FF. GENERAL AUTHENTICATE uses INS 87, with P1 naming the algorithm (11 for ECC P-256) and P2 the key: 9A for PIV authentication, 9E for card authentication. Long data is split across several commands (command chaining), and long responses are collected with GET RESPONSE when the card returns status 61 xx.
Sending APDUs yourself
The SELECT command for the PIV application, with the final Le byte of 00, is 00 A4 04 00 09 A0 00 00 03 08 00 00 10 00 00. With a USB smart-card reader and a smart-card utility, select the reader and send that command. The card returns application information followed by its status word. Avoid sending VERIFY with guesses: each wrong PIN uses up a try.
Secure messaging
Commands can be protected by secure messaging: encrypted and integrity-protected with session keys established between the reader and card. In PIV, the key-establishment protocol authenticates the card application to the reader. The optional virtual contact interface builds on this to protect the PIN and sensitive data over the contactless interface.
Sources
Draft lesson, awaiting technical review · Last updated 1 December 2026