Parse and visualize EMV TLV hex streams into clear tree structures.
Tag-Length-Value (TLV) is a binary encoding scheme used extensively in telecommunications and EMV (chip-and-pin credit cards). Instead of using delimiters like commas or brackets, every piece of data is serialized into three distinct parts:
5A represents the PAN/Account Number).EMV cards specifically use a subset of ASN.1 called BER-TLV (Basic Encoding Rules). BER-TLV supports complex nesting. A "Value" can actually contain another complete TLV structure inside it.
To determine if a tag contains raw data or nested tags, parsers check the binary bits of the Tag byte. If the 6th bit (bit 5) is set to 1, the tag is "Constructed" (nested). If it is 0, the tag is "Primitive" (raw data).
Why do credit card chips use TLV instead of JSON? Bandwidth and Memory.
Smart card chips have kilobytes of memory. JSON includes heavy text overhead (quotes, braces, literal string keys like "accountNumber": "..."). TLV strips all of this away. The identifier is just 1 or 2 bytes, the length is 1 byte, and the data is packed as raw binary. This allows a complete transaction cryptogram to fit into a tiny, ultra-fast payload.
The most common bug when parsing EMV TLV is mishandling the Length byte. If the data is less than 128 bytes, the Length is a simple 1-byte integer.
However, if the data is 128 bytes or larger, BER-TLV uses a multi-byte length. The first byte will have its highest bit set to 1 (e.g., 0x82), indicating that the next 2 bytes contain the actual length. Naive parsers that assume the Length is always exactly 1 byte will catastrophically misread the rest of the stream.
When you dip your chip card, the terminal reads TLV tags like:
Why do EMV smart cards use TLV encoding instead of JSON?