PEM is a text format with BEGIN and END lines, DER is the same data in raw binary, and PKCS12 is a password protected bundle that can hold a private key and certificates together. Web servers usually want PEM, Java keystores use PKCS12 by default, and openssl converts between all three.
What each format is
PEM. RFC 7468 defines the textual encoding used for certificates and keys. The data is base64, wrapped between a BEGIN line and a matching END line. The label on those lines says what the content is, such as CERTIFICATE. A single PEM file can hold several blocks, which is how a full chain file works.
DER. The binary encoding of the same structure. It is what you get if you strip the wrapper and decode the base64. Extensions like .der and .cer are common, though extensions are conventions, not rules.
PKCS12. A container, often with the extension .p12 or .pfx. It can bundle a private key with its certificate chain under a password. Since JDK 9, Java's default keystore implementation is PKCS12, according to the keytool documentation.
Which tool wants what
| Tool or platform | Typical input |
|---|---|
| Nginx, Apache | PEM certificate chain and PEM key |
| Node.js extra CA setting | PEM file of certificates |
| Java keystores | PKCS12 (default since JDK 9) |
| Many Windows and appliance imports | PKCS12 or DER |
Converting with openssl
# PEM to DER
openssl x509 -in cert.pem -outform DER -out cert.der
# DER to PEM
openssl x509 -in cert.der -inform DER -outform PEM -out cert.pem
# PEM key and chain into PKCS12
openssl pkcs12 -export -inkey privkey.pem -in fullchain.pem -out bundle.p12
The x509 command documents input and output format options for PEM and DER.
Reading a file without guessing
To see what a PEM file holds, print it with the x509 command and the text option. For a DER file add the input format option. For a PKCS12 bundle, openssl pkcs12 will list the contents after you supply the password. If a tool says it cannot parse your file, the format is the first thing to check, and the label on the BEGIN line is the second, because a key and a certificate carry different labels. See reading certificate fields.
Mistakes to avoid
- Treating the extension as the format. A file named .crt may be PEM or DER. Open it in a text editor. Readable lines starting with BEGIN mean PEM.
- Putting a private key in a file you hand out. Keep key files separate and protected.
- Sending just the leaf. Include the intermediates. See incomplete chains.
- Weak passwords on PKCS12 bundles that you email or store in a shared drive. Treat the file like the key it contains.
Where Safeguard fits
Safeguard scans dependencies and SBOMs for known vulnerabilities, including those in the TLS and crypto libraries your projects pull in, and you can try it with the free scan at gold.safeguard.sh/scan.
Quick check
How do I tell PEM from DER?
Open the file in a text editor. PEM is readable text with BEGIN and END lines, and DER looks like binary noise.
What is the default Java keystore format?
PKCS12, since JDK 9.
Sources
- RFC 7468, Textual Encodings of PKIX, PKCS, and CMS Structures
- Oracle, keytool documentation
- OpenSSL, x509 manual
Last reviewed: 19 October 2026.