How to convert PEM to DER
- Paste the PEM block into the input, or drop a
.pem,.crt,.keyor.csrfile. - Pick the output under Convert to:
- DER – one-line Base64: the PEM body without header lines and line breaks, ready for a JSON field or an environment variable.
- DER – hex: the same bytes as hex, for byte arrays and protocol traces.
- PEM (64 columns) and Public key (PEM) are there for the reverse direction and for extracting a public key.
- Click Download .der to save the binary file, or Copy output for the text form.
The converter detects certificates, CSRs, CRLs, public keys and private keys (PKCS#1, PKCS#8, SEC1 EC), so there is nothing to choose for the input type.
What the conversion does
PEM is a text wrapper around DER. Take this certificate (shortened):
-----BEGIN CERTIFICATE-----
MIIBtzCCAV2gAwIBAgIUfX6gOa1S96OttEsj3WbuIdu0cE0wCgYIKoZIzj0EAwIw
...
-----END CERTIFICATE-----
Drop the two marker lines, join the remaining lines, Base64-decode, and you have the DER file: here 443 bytes starting 30 82 01 b7, the ASN.1 SEQUENCE header. The label in the marker lines is the only information that disappears. DER files carry no label, which is why tools that read DER either need to be told what the file is or have to guess from its structure.
| Form | Size of this certificate | Where it is used |
|---|---|---|
| PEM | 656 bytes | nginx, Apache, HAProxy, most Linux tools |
| One-line Base64 DER | 592 characters | JSON APIs, x5c arrays in JWKs, environment variables |
| DER (binary) | 443 bytes | Java and Windows tools, firmware, application/pkix-cert downloads |
Where you need DER
- Embedded devices and firmware: certificates compiled into C as a byte array are almost always DER. Use the hex output and paste it into an array.
- Apple platforms:
SecCertificateCreateWithDatatakes DER data, not PEM text. - The
x5cparameter of a JWK and the<ds:X509Certificate>element in SAML metadata hold Base64 DER without PEM headers. - CA Issuers URLs in certificates usually serve a DER
.cerfile. - Windows:
.cerfiles can be either form, but some older import dialogs and appliances only accept DER.
PEM to DER with OpenSSL, Python and certutil
openssl x509 -in cert.pem -outform der -out cert.der
openssl req -in app.csr -outform der -out app.der
openssl pkey -in key.pem -outform der -out key.der
grep -v -- '-----' cert.pem | tr -d '\n'
The last line prints the one-line Base64 DER of a single-certificate file. In Python, ssl.PEM_cert_to_DER_cert(open("cert.pem").read()) returns the DER bytes of a certificate. On Windows, certutil -decode cert.pem cert.der strips the markers and decodes. More in Base64 with OpenSSL and Base64 in Python.
Common problems
- Several blocks in one file: the text outputs convert every block, but Download .der saves only the first object, because a DER file holds exactly one. Split the chain first or download each certificate from its card in the certificate decoder.
-----BEGIN ENCRYPTED PRIVATE KEY-----: converts fine, but the DER is still encrypted. Decrypting needs the password and is not done here.Proc-Type: 4,ENCRYPTEDheaders: legacy OpenSSL encryption has no DER form. Runopenssl pkey -in key.pem -out plain.pemwith the password first.-----BEGIN OPENSSH PRIVATE KEY-----: not ASN.1 at all, so there is no DER to produce. Use the SSH key tool for its public key.
FAQ
Is PEM just Base64 of DER?
Yes. A PEM file is the DER bytes encoded in Base64, wrapped at 64 characters, between a -----BEGIN label----- and an -----END label----- line. Removing those lines and decoding the Base64 gives the exact DER file.
How do I convert a PEM private key to DER?
Paste it here and choose DER – one-line Base64 or Download .der, or run openssl pkey -in key.pem -outform der -out key.der. The key never leaves the page, and its secret values are not displayed.
Why is my DER file smaller than the PEM?
Base64 turns every 3 bytes into 4 characters, and PEM adds line breaks and two header lines. A 443-byte DER certificate becomes a 656-byte PEM file, about 48% larger.