PEM, DER, CRT, and CER: X.509 Encodings and Conversions - SSL.com (2024)

You may have seen digital certificate files with a variety of filename extensions, such as .crt, .cer, .pem, or .der. These extensions generally map to two major encoding schemes for X.509 certificates and keys: PEM (Base64 ASCII), and DER (binary). However, there is some overlap and other extensions are used, so you can’t always tell what kind of file you are working with just from looking at the filename; you may need to open it in a text editor and take a look for yourself.

As you work with digital certificates, you may find yourself with the need to convert between PEM and DER files, view their contents as human-readable text, or combine them into common container formats like PKCS#12 or PKCS#7. This guide points out the major differences between PEM and DER files and common filename extensions associated with them. It also provides visual examples of each encoding, and illustrates some common file format conversions with OpenSSL.

What is OpenSSL?
OpenSSL is a very useful open-source command-line toolkit for working with X.509 certificates, certificate signing requests (CSRs), and cryptographic keys. If you are using a UNIX variant like Linux or macOS, OpenSSL is probably already installed on your computer. If you would like to use OpenSSL on Windows, you can enable Windows 10’s Linux subsystem or install Cygwin.

Need an SSL certificate? SSL.com has you covered. Compare certificates to find the right choice for you, from S/MIME and code signing certificates and more.

COMPARE HERE

PEM

PEM (originally “Privacy Enhanced Mail”) is the most common format for X.509 certificates, CSRs, and cryptographic keys. A PEM file is a text file containing one or more items in Base64 ASCII encoding, each with plain-text headers and footers (e.g. -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----). A single PEM file could contain an end-entity certificate, a private key, or multiple certificates forming a complete chain of trust. Most certificate files downloaded from SSL.com will be in PEM format.

PEM Filename Extensions

PEM files are usually seen with the extensions .crt, .pem, .cer, and .key (for private keys), but you may also see them with different extensions. For example, the SSL.com CA bundle file available from the download table in a certificate order has the extension .ca-bundle.

What does a PEM certificate look like?

The SSL/TLS certificate for www.ssl.com is shown below in PEM format (click to view):

Click to View PEM certificate

-----BEGIN CERTIFICATE-----MIIH/TCCBeWgAwIBAgIQaBYE3/M08XHYCnNVmcFBcjANBgkqhkiG9w0BAQsFADByMQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMxEDAOBgNVBAcMB0hvdXN0b24xETAPBgNVBAo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cdT7AJBPueifCoV25JxXuo8d5139gwP1BAe7IBVPx2u7KN/UyOXdZmwMf/TmFGwDdCfsyHf/ZsB2wLHozTYoAVmQ9FoU1JLgcVivqJ+vNlBhHXhlxMdN0j80R9Nz6EIglQjeK3O8I/cFGm/B8+42hOlCId9ZdtndJcRJVji0wD0qwevCafA9jJlHv/jsE+I9Uz6cpCyhsw+lrFdxUgqU58axqeK89FR+No4q0IIO+Ji1rJKr9nkSB0BqXozVnE1YB/KLvdIsuYZJuqb2pKku+zzT6gUwHUTZvBiNOtXL4Nxwc/KT7WzOSd2wP10QI8DKg4vfiNDsHWmB1c4Kji6gOgA5uSUzaGmq/v4VncK5Ur+n9LbfnfLc28J5ft/GotinMyDk3iarF10YlqcOmeX1uFmKbdi/XorGlkCoMF3TDx8rmp9DBiB/-----END CERTIFICATE-----

Common PEM Conversions

In the OpenSSL commands below, replace the filenames in ALL CAPS with the actual paths and filenames you are working with.

View contents of PEM certificate file

openssl x509 -in CERTIFICATE.pem -text -noout 

Convert PEM certificate to DER

openssl x509 -outform der -in CERTIFICATE.pem -out CERTIFICATE.der

Convert PEM certificate with chain of trust to PKCS#7

PKCS#7 (also known as P7B) is a container format for digital certificates that is most often found in Windows and Java server contexts, and usually has the extension .p7b. PKCS#7 files are not used to store private keys. In the example below, -certfile MORE.pem represents a file with chained intermediate and root certificates (such as a .ca-bundle file downloaded from SSL.com).

openssl crl2pkcs7 -nocrl -certfile CERTIFICATE.pem -certfile MORE.pem -out CERTIFICATE.p7b

Convert PEM certificate with chain of trust and private key to PKCS#12

PKCS#12 (also known as PKCS12 or PFX) is a common binary format for storing a certificate chain and private key in a single, encryptable file, and usually have the filename extensions .p12 or .pfx. In the example below, -certfile MORE.pem adds a file with chained intermediate and root certificates (such as a .ca-bundle file downloaded from SSL.com), and -inkey PRIVATEKEY.key adds the private key for CERTIFICATE.crt(the end-entity certificate). Please see this how-to for a more detailed explanation of the command shown.

openssl pkcs12 -export -out CERTIFICATE.pfx -inkey PRIVATEKEY.key -in CERTIFICATE.crt -certfile MORE.crt

After executing the command above you will be prompted to create a password to protect the PKCS#12 file. Remember this password. You will need it to access any certificates and keys stored in the file.

Go to top

DER

DER (Distinguished Encoding Rules) is a binary encoding for X.509 certificates and private keys. Unlike PEM, DER-encoded files do not contain plain text statements such as -----BEGIN CERTIFICATE-----. DER files are most commonly seen in Java contexts.

DER Filename Extensions

DER-encoded files are usually found with the extensions .der and .cer.

What does a DER-encoded certificate look like?

The DER-encoded SSL/TLS certificate for www.ssl.com is shown below (click to view):

Click to View DER certificate

3082 07fd 3082 05e5 a003 0201 0202 10681604 dff3 34f1 71d8 0a73 5599 c141 72300d06 092a 8648 86f7 0d01 010b 0500 3072310b 3009 0603 5504 0613 0255 5331 0e300c06 0355 0408 0c05 5465 7861 7331 10300e06 0355 0407 0c07 486f 7573 746f 6e311130 0f06 0355 040a 0c08 5353 4c20 436f7270 312e 302c 0603 5504 030c 2553 534c2e63 6f6d 2045 5620 5353 4c20 496e 7465726d 6564 6961 7465 2043 4120 5253 41205233 301e 170d 3230 3034 3031 3030 35383333 5a17 0d32 3130 3731 3630 3035 3833335a 3081 bd31 0b30 0906 0355 0406 13025553 310e 300c 0603 5504 080c 0554 65786173 3110 300e 0603 5504 070c 0748 6f757374 6f6e 3111 300f 0603 5504 0a0c 0853534c 2043 6f72 7031 1630 1406 0355 0405130d 4e56 3230 3038 3136 3134 3234 33311430 1206 0355 0403 0c0b 7777 772e 73736c2e 636f 6d31 1d30 1b06 0355 040f 0c145072 6976 6174 6520 4f72 6761 6e69 7a617469 6f6e 3117 3015 060b 2b06 0104 0182373c 0201 020c 064e 6576 6164 6131 13301106 0b2b 0601 0401 8237 3c02 0103 13025553 3082 0122 300d 0609 2a86 4886 f70d0101 0105 0003 8201 0f00 3082 010a 02820101 00c7 85e4 646d bd45 09ce f144 ab2dc0ad 0920 668a 63cb 7b25 b4b6 6d0d 9be98209 0e09 c7b8 8607 a81a c251 5efd a1e96292 4a24 4641 6f72 fa5a 2a29 c51c 34075295 8423 a454 1116 2648 2837 3bc5 a2e36b8e 715d 81e5 969b 9970 a4c1 dc58 e44725e7 505b 33c5 2719 da00 19b7 4d9a 24664a64 e372 cfa5 84cc 60e1 f158 ea50 69884545 8865 2319 147e eb54 7aec bcfa 53828978 b35c 0a6d 3b43 0158 2819 a98b 4f207728 12bd 1754 c39e 49a2 9ade 763f 951ad8d4 901e 2115 3e06 417f e086 debd 465ab3ff ef2e d1d1 1092 1b94 bae7 2ba9 a966486c b8dc 7470 05f0 ca17 061e 58ce c23cc779 7bf7 4efa dd3c b7c3 db8f 3553 4efe6140 30ac 1182 15d9 3ec0 148f 5270 dc4c921e ff02 0301 0001 a382 0341 3082 033d301f 0603 551d 2304 1830 1680 14bf c15a87ff 28fa 413d fdb7 4fe4 1daf a061 5829bd30 7f06 082b 0601 0505 0701 0104 73307130 4d06 082b 0601 0505 0730 0286 41687474 703a 2f2f 7777 772e 7373 6c2e 636f6d2f 7265 706f 7369 746f 7279 2f53 534c636f 6d2d 5375 6243 412d 4556 2d53 534c2d52 5341 2d34 3039 362d 5233 2e63 72743020 0608 2b06 0105 0507 3001 8614 68747470 3a2f 2f6f 6373 7073 2e73 736c 2e636f6d 301f 0603 551d 1104 1830 1682 0b777777 2e73 736c 2e63 6f6d 8207 7373 6c2e636f 6d30 5f06 0355 1d20 0458 3056 30070605 6781 0c01 0130 0d06 0b2a 8468 0186f677 0205 0101 303c 060c 2b06 0104 0182a930 0103 0104 302c 302a 0608 2b06 01050507 0201 161e 6874 7470 733a 2f2f 7777772e 7373 6c2e 636f 6d2f 7265 706f 7369746f 7279 301d 0603 551d 2504 1630 1406082b 0601 0505 0703 0206 082b 0601 05050703 0130 4806 0355 1d1f 0441 303f 303da03b a039 8637 6874 7470 3a2f 2f63 726c732e 7373 6c2e 636f 6d2f 5353 4c63 6f6d2d53 7562 4341 2d45 562d 5353 4c2d 5253412d 3430 3936 2d52 332e 6372 6c30 1d060355 1d0e 0416 0414 00c0 1542 1acf 0e6b6481 daa6 7471 2149 e9c3 e18b 300e 0603551d 0f01 01ff 0404 0302 05a0 3082 017d060a 2b06 0104 01d6 7902 0402 0482 016d0482 0169 0167 0077 00f6 5c94 2fd1 77302214 5418 0830 9456 8ee3 4d13 1933 bfdf0c2f 200b cc4e f164 e300 0001 7133 48686f00 0004 0300 4830 4602 2100 eb17 a588d47c 1a4f fade 961d 9d2f ef3b 1fc2 8e9b4430 4bfc f565 a1d7 fbab 5881 0221 00f206b7 8753 6e43 cf0b a441 a450 8f05 bae7964b 92a0 a7c5 bc50 5918 8e7a 68fd 24007500 9420 bc1e 8ed5 8d6c 8873 1f82 8b222c0d d1da 4d5e 6c4f 943d 61db 4e2f 584da2c2 0000 0171 3348 68dc 0000 0403 00463044 0220 1911 38c3 369b 3517 43f2 4abfbc53 f7b5 07b6 866d 31e6 75ee 968c 21e086f0 de59 0220 561b ff79 520e 9952 ec0711e2 bf97 a56b 4429 24c5 5899 8d09 16dc5c9b abd9 1181 0075 00ee c095 ee8d 72640f92 e3c3 b91b c712 a369 6a09 7b4b 6a1a1438 e647 b2cb edc5 f900 0001 7133 4868f300 0004 0300 4630 4402 207a 22f6 e85acb37 4782 2d57 08de 6e5e c3df 2a05 697d0d0e 1d9d 5a18 60c0 2c6b 1f02 2009 fabba1c3 02e6 dfb5 8e2e 4ce7 168b 98f0 b823e597 dc8f c046 4592 ca23 bb21 0730 0d06092a 8648 86f7 0d01 010b 0500 0382 02010027 aeba be10 9ee8 ea9a 0b92 ac75 379a17fe 709a 1dcd 340d aa8e 2d75 ef8f 0f5fde15 d600 10bb bcc4 5fb4 02de f126 23d88b94 4ac2 2972 3f9e affb 7898 d93f 65c3b4bc 4c9d 38d5 52e1 6882 a9d7 8333 494cd1c9 ea0e 02c2 7b40 00cc 0a51 ca50 3947514d a936 ea3c f18e a282 8bd3 ddbb 27c09362 1103 6aca 6492 6219 2dc3 4b5a 76ea2a8e a5e7 d3a8 2c56 2a16 4d50 d7ca c779a84c 78b7 ab08 8087 0c9b 6e98 1f5b c9a42404 84aa 5cdb 2d3b 8119 2494 1651 b4c8d386 fe1c 5f2c 8c5f bb93 71d4 fb00 904fb9e8 9f0a 8576 e49c 57ba 8f1d e75d fd8303f5 0407 bb20 154f c76b bb28 dfd4 c8e5dd66 6c0c 7ff4 e614 6c03 7427 ecc8 77ff66c0 76c0 b1e8 cd36 2801 5990 f45a 14d492e0 7158 afa8 9faf 3650 611d 7865 c4c74dd2 3f34 47d3 73e8 4220 9508 de2b 73bc23f7 051a 6fc1 f3ee 3684 e942 21df 5976d9dd 25c4 4956 38b4 c03d 2ac1 ebc2 69f03d8c 9947 bff8 ec13 e23d 533e 9ca4 2ca1b30f a5ac 5771 520a 94e7 c6b1 a9e2 bcf4547e 368e 2ad0 820e f898 b5ac 92ab f6791207 406a 5e8c d59c 4d58 07f2 8bbd d22cb986 49ba a6f6 a4a9 2efb 3cd3 ea05 301d44d9 bc18 8d3a d5cb e0dc 7073 f293 ed6cce49 ddb0 3f5d 1023 c0ca 838b df88 d0ec1d69 81d5 ce0a 8e2e a03a 0039 b925 336869aa fefe 159d c2b9 52bf a7f4 b6df 9df2dcdb c279 7edf c6a2 d8a7 3320 e4de 26ab175d 1896 a70e 99e5 f5b8 598a 6dd8 bf5e8ac6 9640 a830 5dd3 0f1f 2b9a 9f43 06207f

Common DER Conversions

In the OpenSSL commands below, replace the filenames in ALL CAPS with the actual paths and filenames you are working with.

View contents of DER-encoded certificate file

openssl x509 -inform der -in CERTIFICATE.der -text -noout

Convert DER-encoded certificate to PEM

openssl x509 -inform der -in CERTIFICATE.der -out CERTIFICATE.pem

Convert DER-encoded certificate with chain of trust and private key to PKCS#12

To convert a DER certificate to PKCS#12 it should first be converted to PEM, then combined with any additional certificates and/or private key as shown above. For a more detailed description of converting DER to PKCS#12, please see this how-to.

Thank you for choosing SSL.com! If you have any questions, please contact us by email at Support@SSL.com, call 1-877-SSL-SECURE, or just click the chat link at the bottom right of this page. You can also find answers to many common support questions in our knowledgebase.

I am an expert in digital certificates and encryption, well-versed in the intricacies of X.509 certificates, encoding schemes like PEM and DER, and practical tools such as OpenSSL. My expertise is grounded in hands-on experience and a profound understanding of the concepts discussed in the provided article.

The article covers the fundamental concepts of digital certificates, focusing on file formats such as PEM and DER, and their associated encoding schemes. It also introduces the OpenSSL toolkit as a powerful command-line utility for working with X.509 certificates, certificate signing requests (CSRs), and cryptographic keys.

Let's break down the key concepts discussed in the article:

PEM (Privacy Enhanced Mail)

  • Format: PEM files are text files with Base64 ASCII encoding, containing plain-text headers and footers (e.g., -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----).
  • Extensions: Commonly seen with extensions such as .crt, .pem, .cer, .key, and others.
  • Conversion Examples:
    • View contents of PEM certificate file: openssl x509 -in CERTIFICATE.pem -text -noout
    • Convert PEM certificate to DER: openssl x509 -outform der -in CERTIFICATE.pem -out CERTIFICATE.der
    • Convert PEM certificate with chain of trust to PKCS#7: openssl crl2pkcs7 -nocrl -certfile CERTIFICATE.pem -certfile MORE.pem -out CERTIFICATE.p7b
    • Convert PEM certificate with chain of trust and private key to PKCS#12: openssl pkcs12 -export -out CERTIFICATE.pfx -inkey PRIVATEKEY.key -in CERTIFICATE.crt -certfile MORE.crt

DER (Distinguished Encoding Rules)

  • Format: DER files are binary encoded and lack plain text statements found in PEM.
  • Extensions: Typically seen with .der and .cer extensions.
  • Conversion Examples:
    • View contents of DER-encoded certificate file: openssl x509 -inform der -in CERTIFICATE.der -text -noout
    • Convert DER-encoded certificate to PEM: openssl x509 -inform der -in CERTIFICATE.der -out CERTIFICATE.pem

OpenSSL

  • Overview: OpenSSL is an open-source command-line toolkit for working with X.509 certificates, CSRs, and cryptographic keys.
  • Usage: It provides various commands for tasks like viewing certificate contents, converting between formats, and creating PKCS#7 or PKCS#12 files.

This comprehensive guide addresses common scenarios encountered while working with digital certificates, providing practical examples using OpenSSL commands. Whether it's viewing certificate details, converting between formats, or creating container files, OpenSSL proves to be an invaluable tool in managing cryptographic assets.

Feel free to reach out if you have any further questions or if there's a specific aspect you'd like more information on.

PEM, DER, CRT, and CER: X.509 Encodings and Conversions - SSL.com (2024)
Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5738

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.