PEM/DER File Types Reference

Crypto file extensions (.pem, .crt, .key, .p12, .jks) with format and content.

Reference for cryptographic file extensions and their PEM/DER/PKCS content types, typical contents, encoding and the OpenSSL or keytool commands to inspect each one.

What is the difference between PEM and DER?

DER is the binary ASN.1 encoding of a certificate or key. PEM wraps that same DER bytes in base64 and adds -----BEGIN/END----- header lines, making it ASCII-safe to paste and email. A .pem file is just base64-encoded DER.

Why every cert file looks different

.pem, .crt, .key, .csr, .p12, .jks — the same underlying objects (certificates and keys) ship under a confusing pile of extensions and two encodings. This reference explains what each extension actually holds, whether it is text or binary, and the one command that dumps it so you never guess again.

How it works

Two encodings underlie nearly everything:

  • DER — the raw binary ASN.1 encoding.
  • PEM — that same DER, base64-encoded, wrapped in -----BEGIN ...----- / -----END ...----- lines so it is safe to paste into text.

Extensions are a hint, not a guarantee. The reliable test is the first bytes:

-----BEGIN CERTIFICATE-----   → PEM (base64 text)
0x30 0x82 ...                 → DER (binary)

Bundle formats package multiple objects: PKCS#12 (.p12/.pfx) holds a key plus its certificate chain in one password-protected binary file, while JKS (.jks) is Java’s keystore managed by keytool. PEM files can also simply concatenate several certificates to form a chain.

Tips and notes

  • Identify format by content, not extension: look for the -----BEGIN marker.
  • Convert with OpenSSL: openssl x509 -in cert.der -inform der -out cert.pem.
  • Keep private keys (.key) permission-locked and never commit them.
  • Prefer PKCS#12 (.p12) over legacy JKS for new Java keystores.