How to Read ASN.1 / DER Structures
Last updated:
To read an ASN.1 / DER structure is to read the binary language every certificate, private key, CSR, and revocation list on your systems is written in. ASN.1 is the notation — the grammar for describing data — and DER, the Distinguished Encoding Rules, is the one canonical way to turn each value into bytes. If those bytes look like line noise to you, you are not alone: most sysadmins meet ASN.1 as an error message, long after the certificate it describes has already broken something. You can paste any DER or PEM blob into the ASN.1 / DER Explorer and get the full annotated tree in your browser — nothing is uploaded — but this article teaches you to read the bytes yourself, so the tree is never a black box.
One language under every certificate, key, and CSR — and why it keeps tripping people up
ASN.1, Abstract Syntax Notation One, is the notation; the X.680 series defines the grammar and X.690 defines the encoding rules, including DER. Every X.509 certificate, every PKCS#8 private key, every CSR, every CRL, every PKCS#7 bundle, and every OCSP response is a value written in this one language. Sysadmins keep tripping over it for a simple reason: the same bytes wear three costumes. A .pem file opens as readable text, a .der file prints as garbage, a .cer file could be either one — and the tools that show you the structure only do so when you ask, so the first time most people look inside a certificate is after something has already failed.
The second tripwire is that ASN.1 describes the shape, not the meaning. Two files can both be perfectly valid DER and mean completely different things; the meaning comes from the schema — RFC 5280 for certificates — and from the OIDs inside. Reading DER is therefore two skills at once: parsing the tag-length-value skeleton, and knowing which schema the top level claims to be. This article covers both, and the explorer automates the first and labels the second as a best-effort guess, never a verdict — because a parser can tell you what a structure says, but only the schema tells you what it means.
TLV: tag, length, value — the whole grammar in three bytes
Every ASN.1 value is three parts: a tag saying what it is, a length saying how many bytes follow, and the value itself. The tag byte packs three facts into eight bits: the top two bits are the class — 00 universal, 01 application, 10 context-specific (the [0] and [3] you see all over certificates), 11 private — bit 6 says constructed (a container holding other values) or primitive (a leaf), and the low five bits are the tag number, with 31 meaning "read more bytes, the number continues". The length is a short form, one byte, for anything under 128 bytes, or a long form: a first byte of 0x80 plus a count n, then n bytes holding the length big-endian. DER forbids the indefinite form, a length byte of 0x80 — a file that uses it is BER, not DER, and a strict DER parser must reject it.
Here is the whole grammar in one worked example — a minimal hand-built example in the same shape as the explorer's demo. 30 0C 02 01 05 06 02 2A 03 0C 03 66 6F 6F reads as: 30, a constructed SEQUENCE (universal tag 16); 0C, twelve content bytes follow; then 02 01 05, an INTEGER one byte long with value 5; 06 02 2A 03, an OBJECT IDENTIFIER two bytes long, where 0x2A is 42, and 42 is 1 × 40 + 2, so the first two arcs are 1.2, then 03 gives 1.2.3; and 0C 03 66 6F 6F, a UTF8String three bytes long spelling "foo". The same fourteen bytes, read back by openssl asn1parse, are printed in the code block below — run it yourself and match each line against the bytes. Once you can walk this example, you can walk any structure: it is the same three-byte rhythm, nested as deep as the schema goes.
Reading a certificate by hand: tbsCertificate, in order
A certificate is a SEQUENCE of three things: tbsCertificate, the part that is signed; signatureAlgorithm; and signatureValue, a BIT STRING. Inside tbsCertificate the fields always come in the same order — version [0], which is v3 for anything modern; serialNumber, an INTEGER; signature, the algorithm identifier, which must match the outer one; issuer, a Name; validity, a SEQUENCE of notBefore and notAfter; subject, a Name; subjectPublicKeyInfo; and then the optional unique identifiers and extensions [3]. If you can find the second SEQUENCE inside the first, you are already looking at the tbsCertificate, and everything after it is just fields in a fixed order.
The part people actually hunt for — the domain names — is not a top-level field at all. SANs live inside extensions [3], under the OID 2.5.29.17 (subjectAltName), as a SEQUENCE of GeneralNames tagged [2] for DNS names, [7] for IP addresses, [1] for email, and [6] for URIs. The commonName, OID 2.5.4.3, in the subject is the legacy place browsers used to look; modern browsers ignore it and read the SAN extension instead, which is why a certificate with a perfect CN and no SAN fails in every browser. If you want one certificate's fields in plain language, the SSL Certificate Parser extracts them; the explorer shows you where each one sits in the tree.
OIDs are the address book: what 2.5.4.3 and 1.2.840.113549.1.1.11 mean
An OID, an object identifier, is a dotted path through a global registration tree, and it is how a file says what a field means without using words. The first two arcs are packed into a single byte — arc one times forty plus arc two, so 1.2 becomes 0x2A, 42 — and later arcs are encoded base-128. Read 2.5.4.3 as X.500 attribute types (2.5.4) and then commonName (3): the name field on every certificate subject. Read 1.2.840.113549.1.1.11 as ISO member body (1.2.840), then RSA (113549), then pkcs-1 (1), then sha256WithRSAEncryption (11) — the signature algorithm on most certificates in the wild.
Why numbers instead of names? Because a name is ambiguous across languages and vendors and a number is not: an OID lets two implementations that never met agree that a field means the same thing. The explorer resolves the arcs you meet most often — X.500 attributes, RSA and PKCS, elliptic curves, X.509 extensions, PKCS#7, OCSP — and prints the dotted form for anything it does not recognise, so an unknown OID is still an address you can look up rather than a bare number. A bare number with no dotted form is a parser giving up; the dotted form is the minimum honest output.
DER vs BER vs PEM: which one do you actually have?
DER is the canonical subset of BER. BER, the Basic Encoding Rules, allows choices: a length in short or long form, an indefinite length terminated by two zero bytes, a primitive type encoded as constructed. DER pins every choice down, so there is exactly one correct encoding of each value — which is the whole point, because a certificate's signature covers the exact tbsCertificate bytes, and if two encodings of the same value existed, the signature could not be checked. PEM is not an encoding at all: it is base64 of the DER bytes with -----BEGIN CERTIFICATE----- armor around them, wrapped at 64 characters per line.
How to tell what you have: open the file. If it starts with -----BEGIN, it is PEM — strip the armor, base64-decode what is left, and you have DER. If it starts with the byte 0x30, a SEQUENCE tag, it is DER or BER; feed it to a strict parser, and a length byte of 0x80 means BER. If a tool says "unable to load", it usually means you handed it PEM when it wanted DER, or the reverse; OpenSSL converts both ways (openssl x509 -outform DER, or -inform DER), and the explorer accepts PEM, base64, hex, or raw DER and tells you which one it detected. A .cer or .crt extension tells you nothing — either encoding can hide behind it.
The same language, different documents: CSR, CRL, PKCS#7, OCSP
Once the TLV rhythm clicks, the rest is vocabulary. A CSR is a SEQUENCE of certificationRequestInfo, signatureAlgorithm, and signatureValue — the same three-part shape as a certificate, with the request info sitting where tbsCertificate sits. A CRL is a SEQUENCE of tbsCertList, signatureAlgorithm, and signatureValue, with the revoked certificates listed inside. A PKCS#7 / CMS SignedData bundle wraps its content under the OID 1.2.840.113549.1.7.2, and an OCSP response is a BasicOCSPResponse carrying one status per certificate. Same bytes, same nesting rules — only the top-level schema changes.
That is also why one parser covers all of them: the explorer parses any DER blob into the same tree, then asks what the top level looks like, and labels its recognition as best-effort. If it cannot recognise the top level, it still shows the whole tree and says so — the tree is the answer either way. And the limits are worth stating plainly, because parsing is not verification. The explorer does not check signatures, does not validate a chain against a trust store, and does not open encrypted PKCS#12 containers. It tells you what a structure says, not whether to trust it. For matching a certificate to its private key, use the Certificate & Key Matcher.
Try it yourself: 14 bytes of DER, read back with OpenSSL
# A hand-built ASN.1 value: SEQUENCE { INTEGER 5, OID 1.2.3, UTF8String "foo" }
# 14 bytes of DER:
30 0C 02 01 05 06 02 2A 03 0C 03 66 6F 6F
# Read it back with OpenSSL:
$ printf '\x30\x0c\x02\x01\x05\x06\x02\x2a\x03\x0c\x03\x66\x6f\x6f' > sample.der
$ openssl asn1parse -inform DER -in sample.der
0:d=0 hl=2 l= 12 cons: SEQUENCE
2:d=1 hl=2 l= 1 prim: INTEGER :05
5:d=1 hl=2 l= 2 prim: OBJECT :1.2.3
9:d=1 hl=2 l= 3 prim: UTF8STRING :foo