Introduction
DER, the Distinguished Encoding Rules, is the binary form of certificates, keys and other security objects. X.509 certificates, PKCS #8 private keys, certificate signing requests and revocation lists are all defined in ASN.1, a notation for data structures, and DER turns them into bytes in exactly one way, so that a signature over those bytes can be checked.
A DER file is the same data as a PEM file without the
base64 text wrapping. Windows and Java often use the binary form, saved as
.cer, .crt or .der. The extensions do not say which
form a file is in: a DER file starts with the byte 30, a PEM file with
-----BEGIN.
Structure
DER data is a tree of tag, length, value fields (see
encoding rules). The tag byte says what the value is:
30 for a SEQUENCE, 02 for an INTEGER, 06 for an
object identifier, 03 for a BIT STRING, 04 for an OCTET STRING,
and so on. A length below 128 is one byte; a longer length is a byte
80 plus the number of length bytes that follow, so a certificate of a
kilobyte or more begins 30 82 and a 2-byte length.
A certificate is a SEQUENCE of three parts: the to-be-signed certificate, with the version, serial number, issuer, validity dates, subject, public key and extensions; the signature algorithm; and the signature itself as a BIT STRING.
0SEQUENCE30 82and the total length4 bytes4tbsCertificate version, serial, issuer, validity, subject, public key, extensionsvaries…signatureAlgorithm an object identifier and parametersvaries…signatureValue a BIT STRINGvaries
Not described
Known, not yet covered
- Reference: the key and signature algorithm parameter structures (RSA, DSA, EC and PKCS #8 keys) beyond the OIDs, the extensions that other documents define (for example the Microsoft and CA/Browser Forum ones, such as signed certificate timestamps), and the PKCS #7 and CMS wrappers (certificates).
- Viewer: there is no viewer for DER files yet.
Also used for
- Commodore 64 cartridge image – Commodore 64 cartridges: a C64 CARTRIDGE header, then one CHIP packet per bank.
- PEM certificate – Keys and certificates as base64 text between BEGIN and END lines.
- PEM certificate – Keys and certificates as base64 text between BEGIN and END lines.
Links
Software
- OpenSSL – command-line toolkit that reads, writes and converts DER files (Windows, macOS, Linux)
- Windows certificate viewer – opens
.cerand.crtfiles (Windows) - Keychain Access – built into macOS, imports and shows certificates (macOS)
- KeyStore Explorer – free key and certificate manager (Windows, macOS, Linux)
Developers
- cryptography – library that loads and writes DER and PEM (Python)
- crypto/x509 – standard library package that parses DER certificates (Go)
- Bouncy Castle – libraries with ASN.1 and certificate support (Java, C#)
Reference
- ITU-T X.690 – the standard that defines BER, CER and DER
- RFC 5280 – the X.509 certificate profile used on the internet