Explainer · Certificates

What is a PEM file and how do you read it

If you have opened a .pem file and seen a line reading -----BEGIN CERTIFICATE-----, that is PEM. Here is what those lines mean, how PEM differs from DER and PKCS#12, and how to read a certificate without any external tools.

PEM in one sentence

PEM is a textual wrapper around a binary certificate. A binary DER structure is encoded as Base64 text and surrounded by a header and footer line. The name comes from history (Privacy-Enhanced Mail); today the format is described by RFC 7468.

The practical advantage: PEM can be sent by email, pasted into a text editor or read on the command line without the binary data being corrupted.

What PEM looks like

-----BEGIN CERTIFICATE-----
MIICkjCCAjigAwIBAgIRAPejXciB/OqJDsnGrmHcdOMwCgYIKoZIzj0EAwIwOzEL
MAkGA1UEBhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczEMMAoG
A1UEAxMDV0UxMB4XDTI2MTExNjE1NDYyMFoXDTI3MDIxNDE2NDYwM1owGTEXMBUG
A1UEAxMOY2xvdWRmbGFyZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAT...
-----END CERTIFICATE-----

Three things are worth noticing:

PEM, DER, PKCS#12 and CRT/KEY

The file extension does not determine the content — the content does. The same .crt file can hold PEM or DER.

FormatWhat it isTypical use
PEMBase64 text with header and footer linesNginx, Apache, Let's Encrypt, most APIs
DERBinary ASN.1 encodingWindows certificate store, Java, some devices
PKCS#12 / PFXBinary container: certificate + private key (+ chain), usually password-protectedWindows/IIS, macOS, import/export
CRT / CERA name that may mean a PEM or DER certificateGeneric certificate file
KEYPrivate key (PEM or DER)Server configuration

One or several certificates in one file

A PEM file can contain several blocks in sequence. A typical server chain is:

  1. Leaf certificate — the certificate for your domain.
  2. Intermediate certificate — the CA certificate proving who issued the leaf.
  3. Root certificate — usually left out of the chain, because clients already know it from their trust store.

Order matters: the leaf always comes first. In Nginx such a file is called fullchain.pem:

ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

In Apache (2.4.8 and newer) a single file containing both the leaf and the chain is often enough:

SSLCertificateFile    /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

Why this matters: if the server sends only the leaf certificate, clients have to find the intermediate themselves. Some clients cope, some do not — the result is “unable to get local issuer certificate” or a broken chain on older devices.

How to read PEM

The fastest route is the ssl.ee PEM decoder: paste one or several certificates and you will see the subject, issuer, validity period, public key, SHA-256 fingerprint and SAN names. Decoding happens entirely in your browser — no request is sent anywhere.

On the command line, use OpenSSL:

# Everything in a human-readable form
openssl x509 -in cert.pem -noout -text

# Just the basics
openssl x509 -in cert.pem -noout -subject -issuer -dates

# SAN names and fingerprint
openssl x509 -in cert.pem -noout -ext subjectAltName
openssl x509 -in cert.pem -noout -fingerprint -sha256

# Check whether the leaf matches the chain
openssl verify -untrusted chain.pem cert.pem

On Windows you can do the same with a built-in tool:

certutil -dump cert.pem

Converting between formats

# DER → PEM
openssl x509 -inform DER -in cert.der -out cert.pem

# PEM → DER
openssl x509 -in cert.pem -outform DER -out cert.der

# PKCS#12 → PEM (certificate + private key)
openssl pkcs12 -in bundle.p12 -out bundle.pem -nodes

# PEM → PKCS#12
openssl pkcs12 -export -out bundle.p12 \
  -inkey key.pem -in cert.pem -certfile chain.pem

-nodes means “no DES”, so the private key is written without an additional passphrase. If you do that, guard the output file permissions carefully.

Private keys and security

A private key starts with BEGIN PRIVATE KEY (PKCS#8), BEGIN RSA PRIVATE KEY (PKCS#1) or BEGIN EC PRIVATE KEY. The rules are simple:

openssl x509 -noout -modulus -in cert.pem | openssl sha256
openssl rsa  -noout -modulus -in key.pem  | openssl sha256

If the hashes match, they belong together. For ECDSA keys, use openssl pkey -pubout and compare the public keys.

Common errors

SymptomCause
The browser says “certificate is not trusted”The chain is missing an intermediate, or the order is wrong.
no start lineThe file is not PEM (it may be DER) or the header lines are damaged.
bad base64 decodeWhitespace, line breaks or truncated lines were introduced while copying.
The private key does not match the certificateThe wrong key was used, or only one of the two was renewed.
The certificate has expiredRenewal was skipped or the server was not reloaded.

Paste a PEM and read every field instantly — no file upload.

Open PEM decoder Check a domain

Frequently asked questions

Does a PEM file contain the private key?

Sometimes yes, sometimes no. A certificate PEM contains only the public part. If the file has a separate BEGIN PRIVATE KEY block, that part is sensitive and must not be shared.

Can I put several certificates in one file?

Yes. That is the normal form of a chain. The order must be leaf → intermediate → (optionally) root.

Why is the content of .crt and .pem sometimes identical?

Because the extension is only a convention. Many CAs hand out PEM content in a file ending in .crt. Check the content, not the name.

Does decoding PEM send the data to a server?

Not with the ssl.ee decoder. All work happens in your browser in JavaScript and no network request is made.