Vaultools
Menu

PEM (Privacy-Enhanced Mail)

PEM is a text format that wraps Base64-encoded binary data, most often certificates and keys, between "BEGIN" and "END" marker lines so it can be copied, emailed and stored as plain text. RFC 7468 describes how it is used today.

What a PEM file looks like

-----BEGIN CERTIFICATE-----
MIIC...several lines of Base64...
-----END CERTIFICATE-----

Between the markers is the binary DER encoding of the object, converted to standard Base64 and wrapped into lines of 64 characters. The marker names what is inside. PEM was originally designed for encrypted email, and the name stuck long after that use faded.

Common labels

LabelContents
CERTIFICATEAn X.509 certificate
CERTIFICATE REQUESTA certificate signing request (CSR)
PUBLIC KEYA public key
PRIVATE KEYAn unencrypted private key (PKCS#8)
ENCRYPTED PRIVATE KEYA password-protected PKCS#8 private key
RSA PRIVATE KEYAn older RSA-specific private key format (PKCS#1)
EC PRIVATE KEYAn older elliptic-curve private key format

A file can hold several blocks back to back. A “chain” or “bundle” file is simply a leaf certificate followed by its intermediates, and sometimes a private key too.

PEM versus DER

DER is the raw binary form and PEM is its text wrapper. The two are interchangeable, and OpenSSL converts between them:

openssl x509 -in cert.der -inform DER -out cert.pem
openssl x509 -in cert.pem -outform DER -out cert.der

File extensions such as .pem, .crt, .cer and .key are conventions only. What matters is what is between the markers, and whether the file is text (PEM) or binary (DER).

Common pitfalls

References

Ads on this page

Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.

Go Pro to remove them →