SSL Certificate Formats: PEM vs DER vs PFX vs P7B vs PKCS#8

SSL Certificate Formats Explained: PEM vs DER vs PKCS#12/PFX vs PKCS#7/P7B vs PKCS#8
Direct answer: certificate formats differ on only two axes — how they are encoded (Base64 text vs binary) and what they contain (certificate only / chain / chain + private key). PEM is Base64 text wrapped in -----BEGIN----- armor (RFC 7468), the default on Nginx and Apache. DER is the same content in binary ASN.1. PFX (PKCS#12, RFC 7292) bundles the private key and chain into one password-protected file, used by IIS and Windows. P7B (PKCS#7, RFC 2315 → RFC 5652) carries the chain only, never the private key. PKCS#8 (RFC 5958) is the algorithm-agnostic container for a private key. Fastest check: open the file — visible -----BEGIN means PEM, binary garbage means DER or PKCS#12.
Comparison table
| Format | Extensions | Encoding | Private key? | Typical use | Spec |
|---|---|---|---|---|---|
| PEM | .pem .crt .cer .key | Base64 text | Depends on content | Nginx, Apache, Linux | RFC 7468 |
| DER | .der .cer | Binary ASN.1 | No (cert only) | Java, Windows import | — |
| PKCS#12 / PFX | .pfx .p12 | Binary | Yes | IIS, Windows, Tomcat | RFC 7292 |
| PKCS#7 / P7B | .p7b .p7c | Base64 or binary | No | Importing the intermediate chain | RFC 2315 → RFC 5652 |
| PKCS#8 | .key .pem | Base64 or DER | Yes (key only) | OpenSSL 3.x, modern servers | RFC 5958 |
Core concepts
PEM (RFC 7468)
Base64 with armor lines. Multiple blocks can be concatenated (leaf first, then intermediates). The header tells you what is inside: CERTIFICATE, PRIVATE KEY (PKCS#8), RSA PRIVATE KEY (PKCS#1), EC PRIVATE KEY (SEC1), ENCRYPTED PRIVATE KEY, CERTIFICATE REQUEST.
DER
The raw binary encoding, no armor. Required by some Java and Windows import paths. PEM and DER convert losslessly; they are not "two different certificates".
PKCS#12 / PFX (RFC 7292)
A password-protected container holding the private key, leaf and chain. It is the de facto format for Windows/IIS. Because it contains a private key, always use a strong export password and never leave it in a public directory.
PKCS#7 / P7B (RFC 2315 → RFC 5652)
Chain only, commonly used to import intermediates into Windows or a Java trust store. It never contains the private key, so you must still have the original key.
PKCS#8 vs PKCS#1 vs SEC1 (RFC 5958)
These describe private key storage only. PKCS#8 is algorithm-agnostic (PRIVATE KEY), PKCS#1 is RSA-specific (RSA PRIVATE KEY), SEC1 is EC-specific (EC PRIVATE KEY). Normalising on PKCS#8 avoids most cross-language issues.
How to identify, convert and verify in 7 steps
Step 1 — Identify what you actually have (never trust the extension)
file cert.crt # "ASCII text" vs "data"
head -n 1 cert.crt # -----BEGIN means PEMStep 2 — Inspect it (Certificate Decoder does this locally in your browser)
openssl x509 -in cert.pem -noout -textStep 3 — PEM ↔ DER
openssl x509 -outform DER -in cert.pem -out cert.der
openssl x509 -inform DER -in cert.der -out cert.pemStep 4 — PEM ↔ P7B (chain)
openssl crl2pkcs7 -nocrl -certfile cert.pem -certfile chain.pem -out bundle.p7b
openssl pkcs7 -print_certs -in bundle.p7b -out bundle.pemStep 5 — PEM + key ↔ PFX
openssl pkcs12 -export -out bundle.p12 -inkey key.pem -in cert.pem -certfile chain.pem
openssl pkcs12 -in bundle.p12 -out bundle.pem # OpenSSL 3.x: add -noenc for an unencrypted keyTwo OpenSSL 3.x gotchas: the old -nodes flag is now -noenc, and legacy PFX files encrypted with RC2/3DES may need -legacy. Exports use AES-256-CBC with PBKDF2 by default.
Step 6 — Normalise the private key to PKCS#8
openssl pkcs8 -topk8 -nocrypt -in key-rsa.pem -out key8.pemStep 7 — Verify after deployment (or use SSL Checker)
openssl s_client -connect example.com:443 -servername example.comTroubleshooting checklist
| Symptom | Cause | Fix |
|---|---|---|
| unable to load certificate | File is actually DER or P7B | Add -inform DER, or convert to PEM first |
| Expecting: TRUSTED CERTIFICATE | Damaged armor lines / stray blank lines | Regenerate the PEM; keep header and footer on their own lines |
| Nginx key values mismatch | Certificate and key are not a pair | See the key-matching guide or use Certificate & Key Matcher |
| IIS rejects the PFX password | Exported by a third-party tool with incompatible crypto | Re-export with openssl pkcs12 -export |
| Java Invalid keystore format | PEM handed to a JKS store | Convert to PKCS#12 first, then keytool -importkeystore |
| Key header says ENCRYPTED PRIVATE KEY | Service cannot start unattended | openssl pkey -in key.pem -out key-plain.pem |
| Certificate broken after email copy | Line wrapping, BOM or CRLF damage | Re-download; never copy from an email body |
| Certificate now expires in 200 days | CA/B Forum SC-081v3 is in force | Fold format checks into your renewal automation |
Further reading
Tools: Certificate Decoder · Format Converter · Certificate & Key Matcher
Related: Check Whether a Certificate Matches Its Private Key · Fixing an Incomplete Certificate Chain · ACME HTTP-01 vs DNS-01
Go deeper: SSL Certificates: The Complete Guide · Certificate Types Compared
FAQ
Can .crt, .cer and .key extensions tell me the format?
No. Extensions are conventions only — a .cer can be PEM or DER. Inspect the content or use file.
Do servers require a PKCS#8 private key?
Not strictly, but PKCS#8 is algorithm-agnostic and travels cleanly between OpenSSL 3.x, Go and Java. Convert back to PKCS#1 only if a legacy system demands it.
Can I remove the password from a PFX?
Yes, but only when operationally necessary, and then lock down file permissions. On OpenSSL 3.x use -noenc.
Does the move to 200-day certificates change any format?
No format changes — only frequency. Build "identify → match check → chain check" into every renewal.
What does Nginx need?
PEM: ssl_certificate = fullchain (leaf + intermediates), ssl_certificate_key = private key.
Free SSL/TLS tools
Verify and inspect your certificates in seconds.
Related Certificate Info
Learn more about choosing and buying certificates.