# Convert PEM to DER

To convert a PEM certificate to DER, run `openssl x509 -in certificate.pem -outform der -out certificate.der`. DER is the raw binary encoding of the same data; PEM is that binary Base64-encoded and wrapped in `-----BEGIN CERTIFICATE-----` header and footer lines. Nothing is added or lost in either direction. Use a different subcommand for other object types: `openssl req` for a CSR and `openssl pkey` for a private key, because each parses a different ASN.1 structure.

Source: https://certguru.io/convert/pem-to-der/
Last updated: 2026-08-19
Commands verified against OpenSSL 3.5.7.

---

## Certificates

*PEM certificate to DER*

```bash
openssl x509 -in certificate.pem -outform der -out certificate.der
```

| Placeholder | What to put there |
| --- | --- |
| `certificate.pem` | The Base64 input, starting with `-----BEGIN CERTIFICATE-----`. |
| `-outform der` | Tells OpenSSL to write raw binary rather than PEM. |
| `certificate.der` | The binary output file. |

The input format is detected automatically, so `-inform pem` is not needed here. Being explicit does no harm in a script where the input might vary.

## Certificate signing requests

A CSR is a different ASN.1 structure, so `openssl x509` will not parse it. Use `openssl req`:

*PEM CSR to DER*

```bash
openssl req -in request.csr -outform der -out request.der
```

## Private keys

`openssl pkey` handles every key algorithm, which makes it the one to remember. The older
`openssl rsa` and `openssl ec` subcommands still work but only for their own key type:

*PEM private key to DER*

```bash
openssl pkey -in private.key -outform der -out private.der
```

> **A DER key is still an unencrypted key**
>
> Converting to binary is not a security measure. Anyone with the file has the key exactly as much as
>   they did before. To actually protect it, encrypt it: `openssl pkey -in private.key -outform der
>   -out private.der -aes256`.

For a public key, add `-pubin` and `-pubout`:

```bash
openssl pkey -pubin -in public.pem -outform der -pubout -out public.der
```

## What each subcommand handles

| PEM header in the file | Subcommand | Object |
| --- | --- | --- |
| `BEGIN CERTIFICATE` | `openssl x509` | An X.509 certificate |
| `BEGIN CERTIFICATE REQUEST` | `openssl req` | A CSR |
| `BEGIN PRIVATE KEY` | `openssl pkey` | PKCS#8 private key, any algorithm |
| `BEGIN RSA PRIVATE KEY` | `openssl rsa` or `openssl pkey` | PKCS#1 RSA private key |
| `BEGIN EC PRIVATE KEY` | `openssl ec` or `openssl pkey` | SEC1 EC private key |
| `BEGIN PKCS7` | `openssl pkcs7` | A PKCS#7 / P7B bundle |
| `BEGIN X509 CRL` | `openssl crl` | A certificate revocation list |

If you are not sure which you have, read the first line:

```bash
head -n1 mystery.pem
```

## Verify the conversion

The most convincing check is that the fingerprint is unchanged, because that hashes the actual
certificate bytes:

*Both commands must print the same fingerprint*

```bash
openssl x509 -in certificate.pem -noout -fingerprint -sha256
openssl x509 -inform der -in certificate.der -noout -fingerprint -sha256
```

Expected output:

```
sha256 Fingerprint=A1:B2:C3:...
sha256 Fingerprint=A1:B2:C3:...
```

> **Telling the two apart without OpenSSL**
>
> A PEM file is text and starts with `-----BEGIN`. A DER file is binary and, for anything built on a
>   standard ASN.1 SEQUENCE, starts with byte `0x30`. `xxd mystery.der | head -1` showing `3082` is a
>   reliable sign you are holding DER.

## Going the other way

See [convert DER to PEM](/convert/der-to-pem/).


## Frequently asked questions

### Does converting to DER change the certificate?

No. PEM is DER that has been Base64-encoded and given header and footer lines. Converting between them re-encodes the same bytes, so the signature stays valid and the fingerprint is unchanged.

### Why does openssl x509 fail on my PEM file?

Because the file is not a certificate. `openssl x509` only parses certificates. If the file begins `-----BEGIN CERTIFICATE REQUEST-----` use `openssl req`, and if it begins `-----BEGIN PRIVATE KEY-----` use `openssl pkey`.

### Can a DER file hold more than one certificate?

Not usefully. DER has no delimiter between objects, so a concatenation of two DER certificates cannot be reliably split. Chains are why PKCS#7 and PKCS#12 exist. PEM can hold many certificates in one file precisely because its BEGIN and END lines act as delimiters.

### What extension should a DER file have?

There is no enforced convention. `.der` and `.cer` are both common, and Windows tooling often uses `.cer` for DER while other platforms use `.cer` for PEM. Never infer the encoding from the extension; check the first byte instead.


## References

- [openssl-x509(1)](https://docs.openssl.org/3.5/man1/openssl-x509/) — -outform der
- [RFC 7468: textual encodings of PKIX structures](https://www.rfc-editor.org/rfc/rfc7468) — defines the PEM armour and what may sit between the BEGIN and END lines

## Related pages

- https://certguru.io/convert/der-to-pem/
- https://certguru.io/formats/pem/
- https://certguru.io/formats/der/
- https://certguru.io/convert/crt-to-pem/
- https://certguru.io/openssl/view-certificate/

--
CertGuru — https://certguru.io
