How to convert DER to PEM
- Drop the
.der,.ceror.crtfile on the box. Binary input is read as bytes. Instead of a file you can paste one-line Base64 DER, or hex such as30 82 01 b7 …. - Keep Convert to on PEM (64 columns).
- Leave PEM label on Auto-detect. The converter reads the ASN.1 and writes
CERTIFICATE,CERTIFICATE REQUEST,PUBLIC KEY,PRIVATE KEYand so on. Pick a label yourself only if a tool insists on a specific one. - Tick Windows line endings (CRLF) if needed, then Copy output or Download .pem.
Switch to Inspect to check what you converted: subject, expiry and fingerprints are on the card.
Where DER files and headerless Base64 come from
| Source | What you get |
|---|---|
| Windows certificate export, “DER encoded binary X.509 (.CER)” | Binary DER |
Java keytool -exportcert without -rfc | Binary DER |
| CA Issuers URL in a certificate (the AIA extension) | Usually a DER .cer |
x5c in a JWK or JWKS | One-line Base64 DER per certificate |
<ds:X509Certificate> in SAML metadata | Base64 DER, sometimes with line breaks |
| Packet captures, HSM and smart card tools | Hex dumps |
All of these become the same PEM. A 443-byte DER certificate turns into a 656-byte PEM: 592 Base64 characters in ten lines, plus the BEGIN and END lines.
The PEM format in brief
RFC 7468 describes what parsers expect, and the output follows it:
-----BEGIN CERTIFICATE-----
MIIBtzCCAV2gAwIBAgIUfX6gOa1S96OttEsj3WbuIdu0cE0wCgYIKoZIzj0EAwIw
...64 characters per line, the last line shorter...
-----END CERTIFICATE-----
- The label in BEGIN and END must match exactly.
- Body lines are 64 characters of standard Base64 with
=padding. Input in the URL-safe alphabet (-and_) or without padding is accepted and written out in the standard form. - Several certificates in one file are concatenated blocks. That is how
fullchain.pemand CA bundles are built. To build one, convert each DER certificate and paste the blocks one after another, leaf first.
DER to PEM with OpenSSL, Python and the shell
openssl x509 -inform der -in cert.cer -out cert.pem
openssl pkey -inform der -in key.der -out key.pem
openssl req -inform der -in app.der -out app.csr
Older OpenSSL builds fail with unable to load certificate if you forget -inform der; recent ones detect DER themselves. For a one-line Base64 string such as an x5c entry:
{ echo '-----BEGIN CERTIFICATE-----'; echo "$B64" | fold -w 64; echo '-----END CERTIFICATE-----'; } > cert.pem
Python has it built in: ssl.DER_cert_to_PEM_cert(open("cert.der", "rb").read()). More recipes are on the OpenSSL and Python pages.
Common problems
- “Not PEM and not valid Base64 DER” or “Not valid DER/ASN.1 at byte …”: the Base64 is damaged, truncated or not DER. A
.p12or.pfxfile is DER too, but its contents are encrypted, so convert it withopenssl pkcs12instead. - Label shows
DATA: the structure was not recognized as a certificate, key or request. The bytes are still converted; set the label yourself if you know what they are. - The file was PEM all along: some
.cerfiles are PEM despite the extension. The output is then the same certificate, re-wrapped, and nothing else needed converting. The certificate decoder shows what is inside. - You need the reverse: PEM to DER gives a
.derdownload, one-line Base64 or hex.
FAQ
How do I know if my .cer file is DER or PEM?
Open it in a text editor. Readable -----BEGIN CERTIFICATE----- text means PEM; unreadable binary means DER, and its first byte is 0x30. The file command on Linux and macOS prints PEM certificate or Certificate, Version=3 for the two cases.
How do I turn the X509Certificate value from SAML metadata into a PEM file?
Paste the Base64 text from <ds:X509Certificate> into the box. It is DER without headers, so the converter adds -----BEGIN CERTIFICATE-----, wraps it at 64 characters and closes the block.
Can I convert a DER private key to PEM here?
Yes. PKCS#8, PKCS#1 RSA and SEC1 EC keys are detected and get the matching label, such as PRIVATE KEY or EC PRIVATE KEY. The conversion is local, and the key values are not shown on the page.
When should I tick Windows line endings (CRLF)?
Only when a Windows tool or a strict parser rejects the file. Most software accepts both, and RFC 7468 allows either line ending in PEM.