{"id":7744,"date":"2018-10-18T14:57:43","date_gmt":"2018-10-18T18:57:43","guid":{"rendered":"https:\/\/www.thesslstore.com\/blog\/?p=7744"},"modified":"2020-08-24T15:40:07","modified_gmt":"2020-08-24T19:40:07","slug":"how-to-convert-a-certificate-to-the-correct-format","status":"publish","type":"post","link":"https:\/\/www.thesslstore.com\/blog\/how-to-convert-a-certificate-to-the-correct-format\/","title":{"rendered":"How to convert a certificate to the correct format"},"content":{"rendered":"<h2>Instructions on how to convert digital certificates from one file format to another<\/h2>\n<p>We\u2019re going to get a little bit technical today and talk about how to convert a certificate to the correct format. While we do have a <a href=\"https:\/\/www.thesslstore.com\/ssltools\/ssl-converter.php\">page on our site that talks about converting file formats for SSL certificates<\/a>, this is a question we get asked a lot and I wanted to take some time and cover it a little more in-depth.<\/p>\n<p>That also means addressing a few of the questions that inevitably arise along the way, such as why shouldn\u2019t I just use a converter tool? And, what is OpenSSL?<\/p>\n<p>Once we unravel everything it will feel a lot less overwhelming. So if you\u2019re if ready to learn how to convert a certificate to the correct format\u2026<\/p>\n<p>Let\u2019s hash it out.<span id=\"newline\"><\/span><\/p>\n<h2>Why would I need know how to convert a certificate to the correct format?<\/h2>\n<p>Before we talk about how to convert a certificate to the correct format, let&#8217;s start with what that even means. There are dozens of different server-types that are in regular use and unfortunately there is no uniform standard for file type. If this annoys you and you\u2019re American, now you know how the rest of the world feels when it has to convert its metric units to US customary units because we thought it would be far more sporting not to count in units of ten.<\/p>\n<span style=\"--tl-form-height-m:150.25px;--tl-form-height-t:121.4583px;--tl-form-height-d:121.4583px;\" class=\"tl-placeholder-f-type-shortcode_12753 tl-preload-form\"><span><\/span><\/span>\n<p>At any rate, this diversity of server types has led to the use of multiple different file formats for digital certificates. Now, aren\u2019t they all X.509 certificates? &#8211; you\u2019re probably asking. Well, yes. And if you wanted us to, we could write an entire article on this topic that discusses Abstract Syntax Notation and byte arrays but I have a feeling that\u2019s going to be a lot more information than you came for. So here\u2019s the abridged version: An X.509 certificate is a type of digital certificate that uses the PKI standard (X.509 v3) to validate that a server is the rightful owner of the associated public key. When you see extensions like:<img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-7746 size-medium\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-182428858-e1539888468584-300x300.jpg\" alt=\"How to convert a certificate to the correct format\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-182428858-e1539888468584-300x300.jpg 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-182428858-e1539888468584-768x768.jpg 768w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-182428858-e1539888468584.jpg 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li>.der<\/li>\n<li>.pem<\/li>\n<li>.crt<\/li>\n<li>.cer<\/li>\n<li>.pkcs7<\/li>\n<li>.p7b<\/li>\n<li>.pkcs8<\/li>\n<li>.pkcs12<\/li>\n<li>.pfx<\/li>\n<li>.p12<\/li>\n<\/ul>\n<p>Those refer to how the certificate is encoded and presented. For lack of a more eloquent definition, encoding is basically just coding of data into a format that can be used by another system. Or put more simply, it&#8217;s coding data so it can be read and used by a computer. One of the most common encoding standards (that you will need to remember in a couple of paragraphs) is ASCII or the American Standard Code for Information Interchange (a far more ubiquitous standard than our measurement system), which is an encoding scheme used for files that contain text.<\/p>\n<p>Now let\u2019s talk a little bit about encoding styles.<\/p>\n<ul>\n<li>.der \u2013 Stands for Distinguished Encoding Rules, a binary encoding format. Windows views these as certificate files and actually exports certificates as .der formatted files but with an extension like .crt or .cer.<\/li>\n<li>.pem \u2013 Stands for Privacy Enhanced Mail, which is amusing considering that PEM basically failed at the function it was designed for, but proved useful as a container format. PEM files are just Base64 encoded DER files.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-7749\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-222671314-300x300.jpg\" alt=\"How to convert a certificate to the correct format\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-222671314-300x300.jpg 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-222671314-768x768.jpg 768w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-222671314-1024x1024.jpg 1024w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-222671314.jpg 1600w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>I can see that confused look on your face, so let\u2019s break this down a little further.<\/p>\n<p>A DER file is an X.509 digital certificate encoded in binary &#8211; 1&#8217;s and 0&#8217;s. Base64 is a binary-to-text encoding scheme, so a PEM file, which is a Base64 encoded DER file, is that same X.509 certificate, but encoded in text, which (remember!) is represented as ASCII.<\/p>\n<p>Now is this starting to make a little more sense?<\/p>\n<p>Ok, let\u2019s keep going.<\/p>\n<p>DER files are rarely used outside of Windows, so we\u2019ll stop with them. But, remember how we said the PEM is a container? That\u2019s because it can contain anything from just the digital certificate itself, to the entire certificate chain and the keypair. Unfortunately, not all browsers will recognize files with the .pem extension as certificates, so a lot of times you\u2019ll see a different extension affixed to the end of the a PEM file (and also DER files):<\/p>\n<ul>\n<li>.cert<\/li>\n<li>.crt<\/li>\n<li>.cer<\/li>\n<\/ul>\n<p>So when talking about how to convert a certificate to the correct format, you could be talking about how it&#8217;s encoded or how it&#8217;s presented. Now, there are a few other ways to present a certificate beyond PEM and DER. PKCS or Public Key Cryptography Standards, generally you see PKCS 7, PKCS8 and PKCS12. Let\u2019s start with PKCS7, which was originally defined by the company RSA before being turned over to IETF. It is a multi-purpose format for encrypted and signed data to be disseminated. It eventually evolved into Cryptographic Message Syntax, CMS, but just like with SSL and TLS, PKCS7 is the colloquial name we all still use. It\u2019s an open standard, it\u2019s supported by Windows. One thing to note though is that it cannot contain a private key. PKCS7 gets used a lot of with email certificates and forms the basis for S\/MIME secure email.<\/p>\n<p>PKCS8 is a similar standard used for carrying private keys. And finally, we have PKCS12, which provides better security via encryption. Much like a PEM file it can contain anything from the single certificate to the entire certificate chain and key pair, but unlike PEM it\u2019s a fully encrypted password-guarded container. If, during the generation of an SSL certificate you\u2019re prompted for a password, it can be used to open the certificate if it\u2019s in the PKCS12 format.<\/p>\n<h2>Wouldn\u2019t it be easier to do this if I just used a tool?<\/h2>\n<p>Absolutely. It would also be a lot riskier. While generally, we\u2019d like to think you could trust all of the websites that host this kind of tool, uploading your digital certificate anywhere but your own server is generally ill-advised. And by that I mean, don\u2019t use an online tool to convert your digital certificates to different file formats. Do it on your server using OpenSSL commands.<\/p>\n<p>Which leads us to the next inevitable question\u2026<\/p>\n<h2>What is OpenSSL?<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-7747\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-Coding-Desktop-Screen-Vector-I-248939263-300x300.jpg\" alt=\"How to convert a certificate to the correct format\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-Coding-Desktop-Screen-Vector-I-248939263-300x300.jpg 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-Coding-Desktop-Screen-Vector-I-248939263-768x768.jpg 768w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-Coding-Desktop-Screen-Vector-I-248939263-1024x1024.jpg 1024w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-Coding-Desktop-Screen-Vector-I-248939263.jpg 1600w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>OpenSSL is a software library. A computer doesn\u2019t innately know how to do anything. You have to teach it. A software library is a collection of code, scripts, configurations and procedures that helps facilitate a given function. For instance, if you\u2019re writing a piece of software that\u2019s going to require a lot of mathematical calculations it only makes sense to add a mathematical software library so that you don\u2019t have to write a whole bunch of complex mathematical functions yourself.<\/p>\n<p>Now apply that concept to SSL. OpenSSL is a software library that enables the SSL\/TLS protocol on pretty much every server under the sun. Yes, it\u2019s that ubiquitous. So, while there may not be a universal file format for X.509 certificates, there is at least a universal language for manipulating them on servers. OpenSSL is written in the C programming language, which makes it extremely accessible to anyone with even a rudimentary knowledge of programming.<\/p>\n<p>So, now let\u2019s go over how to convert a certificate to the correct format.<\/p>\n<h2>How to convert a certificate to the correct format<\/h2>\n<p>Converting X.509 to PEM \u2013 This is a decision on how you want to encode the certificate (don\u2019t pick DER unless you have a specific reason to).<\/p>\n<pre>openssl x509 -in certificatename.cer -outform PEM -out certificatename.pem<\/pre>\n<p>Converting DER to PEM \u2013 Binary encoding to ASCII<\/p>\n<pre>openssl x509 -inform der -in certificatename.der -out certificatename.pem<\/pre>\n<p>Converting PEM to DER \u2013 ASCII to Binary<\/p>\n<pre>openssl x509 -outform der -in certificatename.pem -out certificatename.der<\/pre>\n<p>Converting PEM to PKCS7 \u2013 PKCS7 files can only contain certificates and certificate chains, never private keys.<\/p>\n<pre>openssl crl2pkcs7 -nocrl -certfile certificatename.pem -out certificatename.p7b -certfile CACert.cer<\/pre>\n<p>Converting PKCS7 to PEM \u2013 Remember, this file will not include the keypair.<\/p>\n<pre>openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.pem<\/pre>\n<p>Converting PKCS12 \u00a0to PEM \u2013 Also called PFX, PKCS12 containers can include certificate, certificate chain and private key. They are password protected and encrypted.<\/p>\n<p>openssl pkcs12 -in certificatename.pfx -out certificatename.pem<\/p>\n<p>Converting PKCS12 to PKCS8 \u2013 PKCS8 is similar to PKCS7, only it\u2019s intended for private key storage and can be encrypted with a password.<\/p>\n<p>This takes two steps:<\/p>\n<pre>openssl pkcs12 -in certificatename.pfx -nocerts -nodes -out certificatename.pem\n\nopenSSL pkcs8 -in certificatename.pem -topk8 -nocrypt -out certificatename.pk8<\/pre>\n<p>Converting PKCS7 to PKCS12 \u2013 This requires two steps as you\u2019ll need to combine the private key with the certificate file.<\/p>\n<pre>openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.cer\n\nopenssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile\u00a0 cacert.cer<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Instructions on how to convert digital certificates from one file format to another We\u2019re going to get a little bit technical today and talk about how to convert a certificate&#8230;<\/p>\n","protected":false},"author":6,"featured_media":7745,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":"","tve_updated_post":"","tve_custom_css":"","tve_user_custom_css":"","tve_globals":{},"tcb2_ready":0,"tcb_editor_enabled":0,"tve_landing_page":"","_tve_header":"","_tve_footer":""},"categories":[130],"tags":[9057],"class_list":["post-7744","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-everything-encryption","tag-digital-certificates","post-with-tags"],"views":122996,"jetpack_featured_media_url":"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/10\/bigstock-Cloud-Computing-Data-Or-Crypt-248166637.jpg","_links":{"self":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts\/7744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/comments?post=7744"}],"version-history":[{"count":0,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts\/7744\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/media\/7745"}],"wp:attachment":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/media?parent=7744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/categories?post=7744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/tags?post=7744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}