brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: openssl x509 -inform der turns a binary certificate into PEM

Openssl
~/tips/tip-openssl-der-to-pem

openssl x509 -inform der -in cert.cer -out cert.pem

Convert a .cer or .der certificate into the text PEM format Linux software expects.

A certificate downloaded from Windows, a browser or a router is often a binary DER file with a .cer or .crt name. nginx and most Linux tools want the PEM text form.

First see which one you have. PEM is text and starts with -----BEGIN CERTIFICATE-----; DER is binary:

head -c 30 cert.cer; echo
openssl x509 -inform der -in cert.cer -out cert.pem

After the conversion, cert.pem holds the same certificate in base64 between the BEGIN and END lines. The other way works with -outform der:

openssl x509 -in cert.pem -outform der -out cert.der

The file name tells you nothing, which is why I’d check the first bytes before guessing. A .crt can be either format, and a .cer from Windows is usually DER, but not always. If openssl x509 -in file without options fails with Could not find certificate or a PEM error, try -inform der.

This is for a single certificate. Keys have their own command, openssl pkey -inform der. Files with several certificates and a key in one, like .pfx or .p12, are PKCS#12 and need openssl pkcs12. A .p7b bundle is PKCS#7, which openssl pkcs7 -print_certs unpacks.

Further reading: OpenSSL: openssl-x509, OpenSSL: format options

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d All Openssl tips (34) All topics

Link