{"id":2612,"date":"2013-10-29T15:33:32","date_gmt":"2013-10-29T07:33:32","guid":{"rendered":"http:\/\/rmohan.com\/?p=2612"},"modified":"2013-10-29T15:33:32","modified_gmt":"2013-10-29T07:33:32","slug":"der-vs-crt-vs-cer-vs-pem","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2612","title":{"rendered":"DER vs. CRT vs. CER vs. PEM"},"content":{"rendered":"<p>Certificates and Encodings<\/p>\n<p>At its core an X.509 certificate is a digital document that has been encoded and\/or digitally signed according to RFC 5280.<\/p>\n<p>In fact, the term X.509 certificate usually refers to the IETF\u2019s PKIX Certificate and CRL Profile of the X.509 v3 certificate standard, as specified in RFC 5280, commonly referred to as PKIX for Public Key Infrastructure (X.509).<br \/>\nX509 File Extensions<\/p>\n<p>The first thing we have to understand is what each type of file extension is.   There is a lot of confusion about what DER, PEM, CRT, and CER are and many have incorrectly said that they are all interchangeable.  While in certain cases some can be interchanged the best practice is to identify how your certificate is encoded and then label it correctly.  Correctly labeled certificates will be much easier to manipulat<br \/>\nEncodings (also used as extensions)<\/p>\n<p>    .DER = The DER extension is used for binary DER encoded certificates. These files may also bear the CER or the CRT extension.   Proper English usage would be \u201cI have a DER encoded certificate\u201d not \u201cI have a DER certificate\u201d.<br \/>\n    .PEM = The PEM extension is used for different types of X.509v3 files which contain ASCII (Base64) armored data prefixed with a \u201c\u2014\u2013 BEGIN \u2026\u201d line.<\/p>\n<p>Common Extensions<\/p>\n<p>    .CRT = The CRT extension is used for certificates. The certificates may be encoded as binary DER or as ASCII PEM. The CER and CRT extensions are nearly synonymous.  Most common among *nix systems<br \/>\n    CER = alternate form of .crt (Microsoft Convention) You can use MS to convert .crt to .cer (.both DER encoded .cer, or base64[PEM] encoded .cer)  The .cer file extension is also recognized by IE as a command to run a MS cryptoAPI command (specifically rundll32.exe cryptext.dll,CryptExtOpenCER) which displays a dialogue for importing and\/or viewing certificate contents.<br \/>\n    .KEY = The KEY extension is used both for public and private PKCS#8 keys. The keys may be encoded as binary DER or as ASCII PEM.<\/p>\n<p>The only time CRT and CER can safely be interchanged is when the encoding type can be identical.  (ie  PEM encoded CRT = PEM encoded CER)<br \/>\nCommon OpenSSL Certificate Manipulations<\/p>\n<p>There are four basic types of certificate manipulations. View, Transform, Combination , and Extraction<br \/>\nView<\/p>\n<p>Even though PEM encoded certificates are ASCII they are not human readable.  Here are some commands that will let you output the contents of a certificate in human readable form;<br \/>\nView PEM encoded certificate<\/p>\n<p>Use the command that has the extension of your certificate replacing cert.xxx with the name of your certificate<br \/>\nopenssl x509 -in cert.pem -text -noout openssl x509 -in cert.cer -text -noout openssl x509 -in cert.crt -text -noout<br \/>\n1<br \/>\n2<br \/>\n3<\/p>\n<p>openssl x509 -in cert.pem -text -noout<br \/>\nopenssl x509 -in cert.cer -text -noout<br \/>\nopenssl x509 -in cert.crt -text -noout<\/p>\n<p>If you get the folowing error it means that you are trying to view a DER encoded certifciate and need to use the commands in the \u201cView DER encoded certificate  below\u201d<\/p>\n<p>unable to load certificate 12626:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:647:Expecting: TRUSTED CERTIFICATE<br \/>\n1<br \/>\n2<\/p>\n<p>unable to load certificate<br \/>\n12626:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:647:Expecting: TRUSTED CERTIFICATE<\/p>\n<p>View DER encoded Certificate<\/p>\n<p>openssl x509 -in certificate.der -inform der -text -noout<br \/>\n1<\/p>\n<p>openssl x509 -in certificate.der -inform der -text -noout<\/p>\n<p>If you get the following error it means that you are trying to view a PEM encoded certificate with a command meant for DER encoded certs. Use a command in the \u201cView PEM encoded certificate above<br \/>\nunable to load certificate 13978:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1306: 13978:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:380:Type=X509<br \/>\n1<br \/>\n2<br \/>\n3<\/p>\n<p>unable to load certificate<br \/>\n13978:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1306:<br \/>\n13978:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:380:Type=X509<\/p>\n<p>Transform<\/p>\n<p>Transforms can take one type of encoded certificate to another. (ie. PEM To DER conversion)<br \/>\nPEM to DER<\/p>\n<p>openssl x509 -in cert.crt -outform der -out cert.der<br \/>\n1<\/p>\n<p>openssl x509 -in cert.crt -outform der -out cert.der<\/p>\n<p>DER to PEM<\/p>\n<p>openssl x509 -in cert.crt -inform der -outform pem -out cert.pem<br \/>\n1<\/p>\n<p>openssl x509 -in cert.crt -inform der -outform pem -out cert.pem<\/p>\n<p>Combination<\/p>\n<p>In some cases it is advantageous to combine multiple pieces of the X.509 infrastructure into a single file.  One common example would be to combine both the private key and public key into the same certificate.<\/p>\n<p>The easiest way to combine certs keys and chains is to convert each to a PEM encoded certificate then simple copy the contents of each file into a new file.   This is suitable for combining files to use in applications lie Apache.<br \/>\nExtraction<\/p>\n<p>Some certs will come in a combined form.  Where one file can contain any one of: Certificate, Private Key, Public Key, Signed Certificate, Certificate Authority (CA), and\/or Authority Chain.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Certificates and Encodings<\/p>\n<p>At its core an X.509 certificate is a digital document that has been encoded and\/or digitally signed according to RFC 5280.<\/p>\n<p>In fact, the term X.509 certificate usually refers to the IETF\u2019s PKIX Certificate and CRL Profile of the X.509 v3 certificate standard, as specified in RFC 5280, commonly referred to as [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2612"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2612"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2612\/revisions"}],"predecessor-version":[{"id":2613,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2612\/revisions\/2613"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}