Recognise the format, not the extension

.crt and .cer are just names — either PEM or DER can be behind them. What counts is the content:

file certificate.crt head -1 certificate.crt -----BEGIN CERTIFICATE----- → PEM (text, Base64) -----BEGIN PKCS7----- → P7B as PEM binary data / "Certificate, Version=3" → DER
  • PEM (.pem, .crt) — text, one or more objects. Postfix, Dovecot, nginx, Apache and HAProxy want this format.
  • DER (.der, .cer) — binary, exactly one certificate. For Java, the Windows import and some appliances.
  • P7B (.p7b, .p7c) — certificates only (the chain), no key. Windows and Tomcat; often how the CA delivers it.
  • PFX (.pfx, .p12) — certificate, chain and key. Windows, IIS, Exchange — see Create and extract a PFX.

PEM and DER

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

The same applies to the private key with openssl pkey:

openssl pkey -in privkey.pem -outform DER -out privkey.der openssl pkey -in privkey.der -inform DER -out privkey.pem

DER always holds exactly one object. A PEM file with certificate and chain yields only the first certificate with openssl x509 -outform DER — the rest is silently dropped.

P7B to PEM and back

# P7B (PEM) → PEM openssl pkcs7 -in chain.p7b -print_certs -out chain.pem # P7B (DER) → PEM openssl pkcs7 -in chain.p7b -inform DER -print_certs -out chain.pem # PEM → P7B openssl crl2pkcs7 -nocrl -certfile cert.pem -certfile intermediate.pem -out chain.p7b

-print_certs writes a subject= and an issuer= line in front of each certificate. Most servers do not mind; if you want them gone, filter with grep -v -E '^(subject|issuer)='.

Assembling fullchain.pem correctly

Mail and web servers usually want one file with the server certificate and the intermediates. The order is fixed: your own certificate first, then each intermediate towards the root.

cat cert.pem intermediate.pem > fullchain.pem
  • The root certificate does not belong in it. The verifier has it anyway; sending it only lengthens the handshake.
  • Wrong order breaks verification with strict clients, even when every part is present.
  • Check the line ending: if cert.pem lacks the newline after -----END CERTIFICATE-----, cat glues both blocks into one invalid line.
  • Windows line endings (\r\n) from a CA's mail are fine for openssl but not for every program — run dos2unix or pass the file through openssl x509 once.

Whether the result is a valid chain is covered in Check certificate and key.

Verify your work

A test mail through your mail server to hello@analyzemy.email shows how it looks from outside: TLS path, SPF, DKIM, DMARC and blacklists in one report.

Analyze your email now

Last updated: · All guides