Skip to content

PEM to DER and DER to PEM converter

Convert a PEM block to DER bytes, or DER bytes back to PEM, as Base64, hex or a file.

Runs in your browser. Nothing you paste is sent to us.

Input

A sample certificate is filled in. Paste your own PEM block.

Output

CERTIFICATE 1,299 bytes

DER as Base64
MIIFDzCCA/egAwIBAgIJAK59SfdKnnZnMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQKDAxFeGFtcGxlIENvcnAxJTAjBgNVBAsMHFNhbXBsZSBjZXJ0aWZpY2F0ZSwgbm90IHJlYWwxGTAXBgNVBAMMEGF1dGguZXhhbXBsZS5jb20wHhcNMjYxMTI1MDk1MTEzWhcNMzYxMTIyMDk1MTEzWjB7MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMRXhhbXBsZSBDb3JwMSUwIwYDVQQLDBxTYW1wbGUgY2VydGlmaWNhdGUsIG5vdCByZWFsMRkwFwYDVQQDDBBhdXRoLmV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzHZIWJTQtoqNPb8rIZ3FJXyR/djxqX4j0o7deufi8zjftkess6qmxhLdhrPQorWnDTX35MAJyEC/x86ytN1mqSSZaVmH5eOTaBP6RTlg/XIligXnIBopE4XHSxcndKuApGmllf65K2xlG0AiJqm/igtvXIg0G9TdpzCCLproDOUc2hmn7lPmYa9myQycv/ABjdo79zi6n5LF9yd2YrcOX6Y4hBLIfwUyvb/KMNWu31QPqZJLPdv0NTlrsiAj1zhv7EYe2QRWWLptOFm1kVZJuKATKhEYXtlA+FtybhJDJpRiwXOwMVoV4f/0ERFtEkXsTaEGTPVg1S07HG26wjjnhQIDAQABo4IBlDCCAZAwbQYDVR0RBGYwZIIQYXV0aC5leGFtcGxlLmNvbYISKi5hdXRoLmV4YW1wbGUuY29thwTAAAIKhxAgAQ24AAAAAAAAAAAAAAABhiRodHRwczovL2F1dGguZXhhbXBsZS5jb20vcmVhbG1zL2FjbWUwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMB0GA1UdDgQWBBTkzI3KGQgPX6kHdgP1slXcbEs2ETAfBgNVHSMEGDAWgBTkzI3KGQgPX6kHdgP1slXcbEs2ETAuBgNVHR8EJzAlMCOgIaAfhh1odHRwOi8vY3JsLmV4YW1wbGUuY29tL2NhLmNybDBdBggrBgEFBQcBAQRRME8wIwYIKwYBBQUHMAGGF2h0dHA6Ly9vY3NwLmV4YW1wbGUuY29tMCgGCCsGAQUFBzAChhxodHRwOi8vY2EuZXhhbXBsZS5jb20vY2EuY3J0MBMGA1UdIAQMMAowCAYGZ4EMAQICMA0GCSqGSIb3DQEBCwUAA4IBAQAZwncnNELdLOg77Y1B7s3Fo7U6+bvOeK+egGnU++rKn0f4y6zAw5m8UCy7gZYX5RpcA2qHoYqKOkcSUSwCDTgCR4lJA+rOtz6ewcDSLOMD3cV6j3P5cgEuQpxyt73S9F31DnmP7liNa59zg1Z2QctQR33XbphZaVJfaF3BFX6uR7nltPqdS3GLBZ1sVjpRVQHTRLKyaihNJZYkIL+nhf7CMMQDNz/JZGeoMkZ6D0f/KosfbupHxj2K5/QYLsYF6uFyFA7ufjXBk5Q3dsA9rctmzwtlrLUdcUcZS+/RCGKAXaIyM7YR3roRfC4lLgxkW0BvB7hxyT4LFux0GITjA0Wu
DER as hex
3082050f308203f7a003020102020900ae7d49f74a9e7667300d06092a864886f70d01010b0500307b310b30090603550406130255533113301106035504080c0a43616c69666f726e696131153013060355040a0c0c4578616d706c6520436f727031253023060355040b0c1c53616d706c652063657274696669636174652c206e6f74207265616c3119301706035504030c10617574682e6578616d706c652e636f6d301e170d3236313132353039353131335a170d3336313132323039353131335a307b310b30090603550406130255533113301106035504080c0a43616c69666f726e696131153013060355040a0c0c4578616d706c6520436f727031253023060355040b0c1c53616d706c652063657274696669636174652c206e6f74207265616c3119301706035504030c10617574682e6578616d706c652e636f6d30820122300d06092a864886f70d01010105000382010f003082010a0282010100cc76485894d0b68a8d3dbf2b219dc5257c91fdd8f1a97e23d28edd7ae7e2f338dfb647acb3aaa6c612dd86b3d0a2b5a70d35f7e4c009c840bfc7ceb2b4dd66a92499695987e5e3936813fa453960fd72258a05e7201a291385c74b172774ab80a469a595feb92b6c651b402226a9bf8a0b6f5c88341bd4dda730822e9ae80ce51cda19a7ee53e661af66c90c9cbff0018dda3bf738ba9f92c5f7277662b70e5fa6388412c87f0532bdbfca30d5aedf540fa9924b3ddbf435396bb22023d7386fec461ed9045658ba6d3859b5915649b8a0132a11185ed940f85b726e1243269462c173b0315a15e1fff411116d1245ec4da1064cf560d52d3b1c6dbac238e7850203010001a382019430820190306d0603551d11046630648210617574682e6578616d706c652e636f6d82122a2e617574682e6578616d706c652e636f6d8704c000020a871020010db8000000000000000000000001862468747470733a2f2f617574682e6578616d706c652e636f6d2f7265616c6d732f61636d65300c0603551d130101ff04023000300e0603551d0f0101ff0404030205a0301d0603551d250416301406082b0601050507030106082b06010505070302301d0603551d0e04160414e4cc8dca19080f5fa9077603f5b255dc6c4b3611301f0603551d23041830168014e4cc8dca19080f5fa9077603f5b255dc6c4b3611302e0603551d1f042730253023a021a01f861d687474703a2f2f63726c2e6578616d706c652e636f6d2f63612e63726c305d06082b060105050701010451304f302306082b060105050730018617687474703a2f2f6f6373702e6578616d706c652e636f6d302806082b06010505073002861c687474703a2f2f63612e6578616d706c652e636f6d2f63612e63727430130603551d20040c300a3008060667810c010202300d06092a864886f70d01010b0500038201010019c277273442dd2ce83bed8d41eecdc5a3b53af9bbce78af9e8069d4fbeaca9f47f8cbacc0c399bc502cbb819617e51a5c036a87a18a8a3a4712512c020d380247894903eaceb73e9ec1c0d22ce303ddc57a8f73f972012e429c72b7bdd2f45df50e798fee588d6b9f7383567641cb50477dd76e985969525f685dc1157eae47b9e5b4fa9d4b718b059d6c563a515501d344b2b26a284d25962420bfa785fec230c403373fc96467a832467a0f47ff2a8b1f6eea47c63d8ae7f4182ec605eae172140eee7e35c193943776c03dadcb66cf0b65acb51d7147194befd10862805da23233b611deba117c2e252e0c645b406f07b871c93e0b16ec741884e30345ae
PEM is DER in Base64 between BEGIN and END lines. The label says what the bytes are; the bytes themselves do not change.

How to use it

  1. Choose PEM to DER or DER to PEM.
  2. Paste a PEM block, or choose a DER file or paste its Base64 or hex.
  3. For DER to PEM, keep the label worked out from the data or choose one.
  4. Copy the result or download it as a file.

What to know

DER is the binary encoding of certificates and keys. PEM is the same bytes in Base64 between BEGIN and END lines, with a label that says what they are.

Java tools and Windows often want DER (.der or .cer files); most Linux software, web servers and Keycloak’s configuration want PEM.

Converting never changes the bytes, so a certificate’s fingerprint is the same in both forms.

PEM and DER: the same bytes, two wrappings

Certificates, keys and certificate requests are ASN.1 structures. DER (Distinguished Encoding Rules, from ITU-T X.690) turns them into exact binary bytes, one encoding per value. DER is what gets hashed and signed.

PEM is a text wrapper around DER: the bytes in Base64, broken into 64-character lines, between a BEGIN and an END line that names what is inside. RFC 7468 describes the format. PEM exists because text survives email, config files, terminals and copy and paste, and binary often does not.

Converting between them never changes the underlying bytes. A certificate has the same fingerprint as PEM and as DER.

How the conversion works

Going from PEM to DER means removing the BEGIN and END lines, joining the Base64 lines and decoding them. Going from DER to PEM means encoding the bytes as Base64, wrapping at 64 characters and adding the lines with the right label.

The start of this page’s sample certificate in both forms
-----BEGIN CERTIFICATE-----
MIIFDzCCA/egAwIBAgIJAK59SfdKnnZnMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNV
...
-----END CERTIFICATE-----

DER (hex):  30 82 05 0f 30 82 03 f7 a0 03 02 01 02 02 09 00 ae 7d ...

Almost every DER certificate or key starts with the byte 30, an ASN.1 SEQUENCE, which is why PEM Base64 for these objects nearly always starts with MI. That is a useful hint when you are unsure what a blob is.

PEM labels and what they mean

The label is not decoration. Software reads it to decide how to parse the bytes, and rejects a mismatch.

LabelContentsStandard
CERTIFICATEAn X.509 certificateRFC 5280
CERTIFICATE REQUESTA PKCS#10 signing requestRFC 2986
PUBLIC KEYSubjectPublicKeyInfo: any public key with its algorithmRFC 5280
PRIVATE KEYPKCS#8: any private key with its algorithmRFC 5958
ENCRYPTED PRIVATE KEYPKCS#8, encrypted with a passphraseRFC 5958
RSA PRIVATE KEYPKCS#1: an RSA private key onlyRFC 8017
RSA PUBLIC KEYPKCS#1: an RSA public key onlyRFC 8017
EC PRIVATE KEYSEC1: an elliptic curve private keyRFC 5915
X509 CRLA certificate revocation listRFC 5280

Changing the label does not convert the contents. A PKCS#1 key relabelled PRIVATE KEY is still PKCS#1 inside and will fail to parse. Converting between key formats needs a tool that rewrites the structure, such as openssl pkey.

File extensions do not tell you the format

Extensions are conventions, and they overlap. The same .crt file can be PEM on one system and DER on another.

ExtensionUsuallyBut may be
.pemPEM, any contentsSeveral blocks, such as a key and a chain
.crt, .cerA certificatePEM or DER
.derDER, any contents-
.keyA private key in PEMPKCS#1, PKCS#8 or SEC1
.csrA PEM signing requestDER on some systems
.p12, .pfxPKCS#12, a password-protected bundle of key and certificatesNot PEM or DER of a single object; this tool does not read it

The quick test: if the file starts with -----BEGIN, it is PEM. If it is binary and starts with the byte 0x30, it is probably DER.

What this converter does and does not do

  • PEM to DER: decodes the first PEM block, checks it parses as DER, and shows it as Base64 and hex, with a download of the .der file.
  • DER to PEM: reads a DER file from your disk, or DER pasted as Base64 or hex, and wraps it as PEM.
  • It works out the label from the structure for certificates, requests, public keys and common private key formats, and lets you choose one when it cannot tell.
  • Files are read in your browser. Nothing is uploaded.
  • It does not convert between key formats such as PKCS#1 and PKCS#8, decrypt encrypted keys, or read PKCS#12 bundles.

How to convert

  1. Choose PEM to DER or DER to PEM.
  2. For PEM to DER, paste the PEM block. For DER to PEM, choose the file or paste its bytes as Base64 or hex.
  3. For DER to PEM, keep the label worked out from the data, or choose one if the tool cannot tell.
  4. Copy the result, or download it as a file.
The same conversions with OpenSSL
# Certificate: PEM to DER and back
openssl x509 -in cert.pem -outform der -out cert.der
openssl x509 -in cert.der -inform der -out cert.pem

# Private key: PEM to DER (PKCS#8)
openssl pkey -in key.pem -outform der -out key.der

# Certificate request
openssl req -in req.pem -outform der -out req.der

Where you meet both formats in identity work

Identity systems mix the two formats freely, which is why conversion comes up so often.

Keycloak configuration

Keycloak reads PEM files for its own TLS certificate and key, and accepts PEM for imported realm keys. Truststores and keystores in Java formats are another option, but PEM is the simplest. If a CA sends a DER certificate, convert it to PEM first.

Bare Base64 in admin screens and metadata

Keycloak’s realm keys page and SAML metadata show certificates as Base64 without the BEGIN and END lines. That is DER in Base64. Paste it into DER to PEM with Base64 selected to get a proper PEM file.

Windows and Java tools

Windows certificate dialogs often export DER .cer files, and some Java tools expect DER. Convert PEM to DER for them, and back again for Linux servers and most other software.

JWKs and the x5c field

A JWK can carry a certificate chain in x5c: each certificate as standard Base64 DER, without line breaks or PEM lines. To read one, paste it into DER to PEM or straight into the certificate decoder.

Common mistakes

  • Renaming a PEM label to make software accept a key. The structure must match the label.
  • Concatenating PEM blocks in the wrong order. For a TLS chain, the server certificate comes first, then each intermediate.
  • Leaving Windows line endings or stray spaces in PEM files that strict parsers reject.
  • Treating Base64url as Base64. JWK values use Base64url; x5c and PEM use standard Base64.
  • Assuming a .crt file is PEM because others were.

Security notes

Certificates and public keys are public. Private keys are not, in any format: DER is no more protected than PEM, it is only binary. If you convert a private key here, it stays in your browser, but treat the downloaded file with the same care as the original and delete copies you do not need.

An unencrypted private key file should be readable only by the service that uses it. On Linux that usually means mode 600 and the service’s own user.

Files with several PEM blocks

One PEM file can hold several blocks one after another. That is how certificate chains and bundles are stored, and it is something DER cannot do: a DER file holds exactly one object.

FileTypical contentsOrder
Chain or full chainServer certificate and intermediatesServer certificate first, then each issuer
CA bundleTrusted root certificatesAny order
Combined key and certificatePrivate key and certificateDepends on the software; some expect the key first

This converter takes the first block of a PEM file. To convert a chain to DER, split it into one file per certificate and convert each. To check a chain’s order, paste it into the certificate decoder, which decodes every block and warns when the order is wrong.

Questions

Frequently asked questions

What is the difference between PEM and DER?

DER is the binary encoding of a certificate or key. PEM is the same bytes in Base64 text between BEGIN and END lines. The content is identical; only the wrapping differs.

How do I convert PEM to DER with OpenSSL?

For a certificate, openssl x509 -in cert.pem -outform der -out cert.der. For a private key, openssl pkey -in key.pem -outform der -out key.der.

Is a .crt file PEM or DER?

It can be either. Open it in a text editor: if it starts with -----BEGIN CERTIFICATE-----, it is PEM; if it is unreadable binary, it is DER.

Does converting change the certificate fingerprint?

No. Fingerprints are computed over the DER bytes, which are the same in both forms.

Can I just change the PEM label from RSA PRIVATE KEY to PRIVATE KEY?

No. Those labels mark different structures, PKCS#1 and PKCS#8. Convert with openssl pkey instead, which rewrites the contents.

What is a .p12 or .pfx file?

A PKCS#12 bundle: usually a private key and its certificate chain, protected by a password. It is neither a single PEM nor a single DER object. OpenSSL’s pkcs12 command extracts its parts.

Why does my Base64 certificate have no BEGIN line?

Many systems, including Keycloak’s keys page and SAML metadata, show just the Base64 of the DER bytes. Paste it into DER to PEM to add the lines.

How can I tell what a DER file contains?

Convert it to PEM here: the tool works out the label for certificates, requests, public keys and common private key formats. On the command line, openssl asn1parse -inform der -in file.der shows the raw structure.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.