All Tools
Tools/EMV TLV Decoder
🔓
EMV & TLVAvailable

EMV TLV Decoder

Decode TLV-encoded hex bytes (e.g. from DE55 / tag 77 response) into a structured, annotated list of EMV tag/length/value records with descriptions.

Examples:
</> Code Implementation
# BER-TLV Parser — decode EMV tag-length-value structures
# No external dependencies required

def parse_tlv(hex_str: str) -> list:
    data = bytes.fromhex(hex_str.replace(" ", ""))
    results, i = [], 0
    while i < len(data):
        # Tag: 1 or 2 bytes
        tag = data[i]
        i += 1
        if (tag & 0x1F) == 0x1F:          # two-byte tag
            tag = (tag << 8) | data[i]; i += 1
        tag_hex = format(tag, "02X") if tag < 256 else format(tag, "04X")
        # Length
        l = data[i]; i += 1
        if l & 0x80:                        # long form
            n = l & 0x7F
            length = int.from_bytes(data[i:i+n], "big"); i += n
        else:
            length = l
        value = data[i:i+length]; i += length
        results.append({"tag": tag_hex, "length": length, "value": value.hex().upper()})
    return results

# Example
tlv = "9F02060000000025009A03260101"
for t in parse_tlv(tlv):
    print(f"Tag: {t['tag']}  Len: {t['length']:02d}  Value: {t['value']}")
# Tag: 9F02  Len: 06  Value: 000000002500
# Tag: 9A    Len: 03  Value: 260101