1️⃣ What is PEM format?
PEM (Privacy-Enhanced Mail) is a text format used to store and transfer keys and certificates. It Base64-encodes binary DER data and wraps it with headers and footers like -----BEGIN <LABEL>----- and -----END <LABEL>-----. Common labels include PUBLIC KEY, PRIVATE KEY, and CERTIFICATE. It is easy to copy, paste, and transmit in text-based workflows, making it one of the most common key exchange formats.
2️⃣ Which other formats are common besides PEM?
- DER: a pure binary format that stores ASN.1 structures directly. It is not human-readable and is common in Java ecosystems.
- HEX: expresses DER binary content as a hexadecimal string, useful for debugging or embedding in code.
- Base64 (without headers): raw DER encoded as Base64 without PEM headers, often used in compact configurations or token payloads.
- PKCS#12 (PFX): a binary container format that can bundle public and private keys together, usually protected by a password and often used by browsers or Windows systems.
3️⃣ When should you use each format?
- PEM: the most universal option, suitable for OpenSSL, web servers (Nginx/Apache), and API exchange.
- DER: commonly used in Java environments or where strict binary storage is required.
- HEX: useful in debugging, embedded systems, or whenever exact byte inspection is needed.
- Base64 (without headers): useful when formatting is constrained or a compact representation is required.
- PKCS#12: useful when both public and private keys must be transported together while protecting the private key with a password.