Xerobit

PEM to DER Converter

Paste a PEM block to extract the raw DER bytes as base64 or hexadecimal, or paste DER data to wrap it in PEM format. The conversion runs entirely in your browser so nothing is uploaded to any server.

PEM to DER: paste the whole PEM block. DER to PEM: paste the DER bytes as base64 or hex.

Used when converting PEM to DER.

Used when converting DER to PEM. Hex may include spaces, colons or a 0x prefix.

Used when converting DER to PEM.

On: DER to PEM only accepts one complete DER element.

Result

MHcCAQEEIIUF0hfq/VRjvm1DmBhgpGVWWVrr059rjaJQ+LCX0SvgoAoGCCqGSM49AwEHoUQDQgAEjRehQpdKM8fonNVVoVEXI5Tf2YJRaIO/NpDhl6GUum3hTdq+MUp1fWKgqzjMptN8mc3WWqVyY7A/4yUxMl+I4g==
  • Direction
    PEM to DER (base64)
  • PEM label
    EC PRIVATE KEY
  • DER size
    121 bytes
  • DER structure
    SEQUENCE, 119 content bytes

By · Published · How we build and test tools

How to use the pem to der converter

  1. Pick the direction: PEM to DER or DER to PEM.
  2. Paste the PEM block, or the DER bytes as base64 or hex, into the input box.
  3. For PEM to DER, choose whether the DER should be shown as base64 or hex.
  4. For DER to PEM, leave the label on Auto-detect or pick one such as CERTIFICATE or PRIVATE KEY.
  5. Read the converted text and the size and structure rows, then copy the result.

What are PEM and DER formats

PEM (Privacy Enhanced Mail) and DER (Distinguished Encoding Rules) are two ways of representing the same ASN.1 binary data used in X.509 certificates, private keys and public keys. DER is the raw binary encoding defined by ITU-T X.690. PEM takes that exact binary payload, encodes it in base64, splits it into lines of 64 characters, and wraps it between header and footer lines like -----BEGIN CERTIFICATE-----.

A single PEM file can hold multiple objects concatenated together, while DER files contain exactly one binary object. When you convert pem to der, you are stripping away the text envelope and decoding the base64 body back to its original bytes.

How the conversion works

PEM to DER is a text-decoding job. The tool finds the -----BEGIN ...----- line and the matching -----END ...----- line, removes the whitespace between them and decodes the remaining base64 into bytes. The base64 check is strict: only A-Z, a-z, 0-9, + and / are allowed, the length must be a multiple of 4 and = padding may appear only at the end. Anything else returns an error instead of a partly decoded result.

DER to PEM goes the other way: read the bytes from base64 or hex, check that they form one complete DER element, encode them as base64, split the text into 64-character lines and add the header and footer. With the label on auto-detect, the tool looks at the ASN.1 shape to choose CERTIFICATE, CERTIFICATE REQUEST, PUBLIC KEY, PRIVATE KEY, ENCRYPTED PRIVATE KEY, RSA PRIVATE KEY, RSA PUBLIC KEY or EC PRIVATE KEY.

A small example: the five bytes 30 03 02 01 01 are a SEQUENCE holding the INTEGER 1. In base64 they are MAMCAQE=, so with the label PRIVATE KEY the PEM is -----BEGIN PRIVATE KEY-----, then MAMCAQE=, then -----END PRIVATE KEY-----.

Common PEM labels

The label inside the BEGIN and END markers tells software what kind of object is stored inside. Choosing the wrong label will not corrupt the bytes, but tools like OpenSSL may refuse to parse the file. Here are the most common labels:

LabelContents
CERTIFICATEX.509 certificate (public key, issuer, validity, extensions)
RSA PRIVATE KEYPKCS#1 RSA private key
PRIVATE KEYPKCS#8 unencrypted private key (any algorithm)
ENCRYPTED PRIVATE KEYPKCS#8 encrypted private key
PUBLIC KEYSubjectPublicKeyInfo structure
CERTIFICATE REQUESTPKCS#10 certificate signing request
X509 CRLCertificate revocation list

When converting DER to PEM with this tool, select the label that matches your data. If you are working with a CSR, you might also use a CSR decoder to inspect the request first.

When to use DER versus PEM

PEM is the default for most web servers, mail systems and command-line tools because it is plain text and easy to copy, email or embed in configuration files. Apache and Nginx expect PEM-formatted certificates and keys.

DER is preferred in Java keystores, Windows certificate stores, smart cards and embedded systems where binary parsing is faster and file size matters. A DER-encoded certificate is about a quarter smaller than its PEM equivalent because it avoids the base64 expansion (4 characters for every 3 bytes) and the line breaks.

If you need to inspect the contents of either format, an SSL certificate decoder can parse the ASN.1 structure and show you the subject, issuer and validity dates.

Command-line equivalents

This browser-based pem to der converter handles quick conversions without installing anything. For batch processing or scripting, OpenSSL provides equivalent commands:

  • PEM to DER: openssl x509 -in cert.pem -outform DER -out cert.der
  • DER to PEM: openssl x509 -inform DER -in cert.der -outform PEM -out cert.pem
  • Private key PEM to DER: openssl rsa -in key.pem -outform DER -out key.der
  • Public key PEM to DER: openssl rsa -pubin -in pub.pem -outform DER -out pub.der
  • DER to single-line base64: openssl base64 -A -in cert.der

The OpenSSL commands read and write files on disk, whereas this tool operates entirely in memory within your browser session.

Worked examples

ExampleInputResult
EC private key PEM to DER (base64)Direction: pem-to-der; Input: -----BEGIN EC PRIVATE KEY----- / MHcCAQEEIIUF0hfq/VRjvm1DmBhgpGVWWVrr059rjaJQ+LCX0SvgoAoGCCqGSM49 / AwEHoUQDQgAEjRehQpdKM8fonNVVoVEXI5Tf2YJRaIO/NpDhl6GUum3hTdq+MUp1 / fWKgqzjMptN8mc3WWqVyY7A/4yUxMl+I4g== / -----END EC PRIVATE KEY-----; DER output format: base64; DER input format: auto; PEM label: auto; Check that the DER is well formed: yesDirection: PEM to DER (base64); PEM label: EC PRIVATE KEY; DER size: 121 bytes; DER structure: SEQUENCE, 119 content bytes
Certificate PEM to DER (hex)Direction: pem-to-der; Input: -----BEGIN CERTIFICATE----- / MIIBgjCCASmgAwIBAgIUEJbg2/LLMJC5rND0lctcTyZDad0wCgYIKoZIzj0EAwIw / FzEVMBMGA1UEAwwMeGVyb2JpdC50ZXN0MB4XDTI2MTEwNTEzNTQxMFoXDTM2MTEw / MjEzNTQxMFowFzEVMBMGA1UEAwwMeGVyb2JpdC50ZXN0MFkwEwYHKoZIzj0CAQYI / KoZIzj0DAQcDQgAEjRehQpdKM8fonNVVoVEXI5Tf2YJRaIO/NpDhl6GUum3hTdq+ / MUp1fWKgqzjMptN8mc3WWqVyY7A/4yUxMl+I4qNTMFEwHQYDVR0OBBYEFDDQHTlx / 8ppMu3YVcA2hDdbVqbstMB8GA1UdIwQYMBaAFDDQHTlx8ppMu3YVcA2hDdbVqbst / MA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDRwAwRAIgDR/jVaFs8JTxMEKl / dGsgLkwsKGk6dZw0DDQwvCy9yJACIDhBxr7S0rNstweXvo/Y2HeoBrOCtxmgllqP / 2zNUIGCx / -----END CERTIFICATE-----; DER output format: hex; DER input format: auto; PEM label: auto; Check that the DER is well formed: yesDirection: PEM to DER (hexadecimal); PEM label: CERTIFICATE; DER size: 390 bytes; DER structure: SEQUENCE, 386 content bytes
Certificate DER hex to PEMDirection: der-to-pem; Input: 3082018230820129a00302010202141096e0dbf2cb3090b9acd0f495cb5c4f264369dd300a06082a8648ce3d04030230173115301306035504030c0c7865726f6269742e74657374301e170d3236313130353133353431305a170d3336313130323133353431305a30173115301306035504030c0c7865726f6269742e746573743059301306072a8648ce3d020106082a8648ce3d030107034200048d17a142974a33c7e89cd555a151172394dfd982516883bf3690e197a194ba6de14ddabe314a757d62a0ab38cca6d37c99cdd65aa57263b03fe32531325f88e2a3533051301d0603551d0e0416041430d01d3971f29a4cbb7615700da10dd6d5a9bb2d301f0603551d2304183016801430d01d3971f29a4cbb7615700da10dd6d5a9bb2d300f0603551d130101ff040530030101ff300a06082a8648ce3d040302034700304402200d1fe355a16cf094f13042a5746b202e4c2c28693a759c340c3430bc2cbdc89002203841c6bed2d2b36cb70797be8fd8d877a806b382b719a0965a8fdb33542060b1; DER output format: base64; DER input format: auto; PEM label: auto; Check that the DER is well formed: yesDirection: DER to PEM; PEM label: CERTIFICATE; Input read as: hexadecimal; DER size: 390 bytes; DER structure: SEQUENCE, 386 content bytes
Tiny DER with a chosen labelDirection: der-to-pem; Input: 30 03 02 01 01; DER output format: base64; DER input format: auto; PEM label: PRIVATE KEY; Check that the DER is well formed: yesDirection: DER to PEM; PEM label: PRIVATE KEY; Input read as: hexadecimal; DER size: 5 bytes; DER structure: SEQUENCE, 3 content bytes

FAQ

Is the DER output identical to the original binary file?

Yes. The base64 or hex produced by this tool represents the exact bytes found between the PEM markers. Writing those bytes to a file gives you a valid DER file.

Why does my DER hex output look different from another tool?

Hex formatting varies. Some tools insert spaces or uppercase letters. This tool outputs lowercase hex with no spaces. The underlying byte values are identical.

Does this tool upload my keys to a server?

No. All processing happens locally in your browser using JavaScript. Your certificates and keys never leave your device.

What happens if I pick the wrong PEM label?

The base64 payload stays the same, but consuming software may reject the file. For instance, labeling a certificate as PRIVATE KEY will cause TLS libraries to fail.

Can I convert multiple PEM blocks at once?

This tool extracts the first PEM block it finds. For files containing a chain of certificates, split them into individual blocks before converting each one.

Can I convert an encrypted private key?

A PKCS#8 file labelled ENCRYPTED PRIVATE KEY converts like any other, and the payload stays encrypted. Legacy PEM keys with Proc-Type: 4,ENCRYPTED headers are refused, so decrypt them with OpenSSL first.

Why does DER to PEM say my bytes are not valid DER?

With the well-formed check on, the input must be exactly one DER element whose length matches the data. Cut-off pasting, extra bytes and text that is not base64 or hex all fail this check. Untick it to wrap arbitrary bytes.