opyeb x509lab

x509lab · Formats

PEM and DER: what actually differs

A certificate file can open as an unreadable pile of characters, or look like plain text. Knowing how PEM and DER relate keeps the file name from misleading you.

One certificate, two representations

An X.509 certificate is defined in ASN.1 and encoded into bytes with DER, the Distinguished Encoding Rules. DER is a binary format with fixed tags and lengths, hard for a person to read. PEM turns those bytes into Base64 and wraps them in a label such as -----BEGIN CERTIFICATE-----. PEM is packaging, not encryption.

Decoding PEM yields DER; wrapping DER in Base64 yields PEM. Both files have the same SHA-256 fingerprint. Tools differ in what they accept, which is why a conversion seems necessary.

What the label tells you

The PEM header names the structure inside. These are the labels you meet around certificates.

LabelContentUsed for
CERTIFICATEOne X.509 certificate (DER)Server certificate, intermediate, root
TRUSTED CERTIFICATECertificate plus trust settings (OpenSSL)OpenSSL trust stores
X509 CRLCertificate revocation listRevocation checks
PKCS7A container of several certificatesChain distribution, S/MIME
CERTIFICATE REQUESTA signing request (CSR)The step before issuance
PRIVATE KEYA private keyHeld by the server. Never share

This tool reads only the CERTIFICATE label. A CSR or CRL is not a certificate, so it is named and skipped, and a PRIVATE KEY header stops the tool with a warning.

Extensions cannot be trusted

.pem, .crt, .cer and .der are conventions. Most .crt files hold PEM text, and a .pem file sometimes holds three certificates in a row. Do not judge by the extension: look at the first byte. DER starts with 0x30 (SEQUENCE) and PEM starts with a dash.

Small pitfalls in Base64

PEM bodies contain line breaks, and a copy can pick up spaces or tabs. Base64 decoding must ignore both. Some tools also omit the padding character. This tool strips whitespace, restores padding and then decodes.

You can copy the explanatory sentence around a certificate as well; only the bytes inside the BEGIN and END block are read.

Questions

Is PEM an encrypted format?

No. It is the DER bytes turned into Base64 and wrapped in BEGIN and END labels. Anyone can decode it, and the public information inside the certificate is readable as is.

What is the difference between .crt and .pem?

Extensions are only a convention. A .crt file most often holds PEM text, and a .pem file can contain several certificates. The first byte of the content is the reliable signal.

What if a DER file opens as garbage text?

DER is binary data that starts with 0x30, so an editor shows it broken. Drop the file into this tool; it reads it and displays the content wrapped in PEM.

Paste PEM, Base64 DER or HEX and the format is detected for you.

Open the tool

This article follows RFC 5280 (X.509), RFC 6125 (host name verification), RFC 6960 (OCSP), RFC 7469 (HPKP), RFC 8555 (ACME) and the CA/Browser Forum Baseline Requirements. Every example certificate is synthetic, made for this site, and tied to no real domain.