{"id":6141,"date":"2016-08-03T16:19:50","date_gmt":"2016-08-03T08:19:50","guid":{"rendered":"http:\/\/rmohan.com\/?p=6141"},"modified":"2016-08-03T16:20:50","modified_gmt":"2016-08-03T08:20:50","slug":"convert-a-pfx-to-a-seperate-key-crt-file","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6141","title":{"rendered":"convert a PFX to a seperate .key\/.crt file"},"content":{"rendered":"<p>So after you installed OpenSSL you can start it from it\u2019s Bin folder. I\u2019d like to put OpenSSL\\Bin in my path so I can start it from any folder. Fire up a command prompt and cd to the folder that contains your .pfx file. First type the first command to extract the private key:<\/p>\n<p>openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]<\/p>\n<p>What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file.  This is the password that you used to protect your keypair when you created your .pfx file.  If you cannot remember it anymore you can just throw your .pfx file away, cause you won\u2019t be able to import it again, anywhere!.  Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.<\/p>\n<p>Now let\u2019s extract the certificate:<\/p>\n<p>openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]<\/p>\n<p>Just press enter and your certificate appears.<\/p>\n<p>Now as I mentioned in the intro of this article you sometimes need to have an unencrypted .key file to import on some devices.  I probably don\u2019t need to mention that you should be carefully. If you store your unencrypted keypair somewhere on an unsafe location anyone can have a go with it and impersonate for instance a website or a person of your company.  So always be extra careful when it comes to private keys! Just throw the unencrypted keyfile away when you\u2019re done with it, saving just the encrypted one.<\/p>\n<p>The command:<\/p>\n<p>openssl rsa -in [keyfile-encrypted.key] -out [keyfile-decrypted.key]<\/p>\n<p>Again you need to enter an import password. This time you need to enter the new password that you created in step 1.  After that you\u2019re done. You decrypted your private key. In the folder you ran OpenSSL from you\u2019ll find the certifcate (.crt) and the two private keys (encrypted and unencrypted).<\/p>\n<p>Update 07-07-2014:<\/p>\n<p>In some cases you might be forced to convert your private key to PEM format. You can do so with the following command:<\/p>\n<p>openssl rsa -in [keyfile-encrypted.key] -outform PEM -out [keyfile-encrypted-pem.key]<\/p>\n<p>dditionally to<\/p>\n<p>openssl pkcs12 -in domain.pfx -clcerts -nokeys -out domain.cer<br \/>\nopenssl pkcs12 -in domain.pfx -nocerts -nodes  -out domain.key<\/p>\n<p>openssl pkcs12 -in domain.pfx -clcerts -nokeys -out domain.cer<br \/>\nopenssl pkcs12 -in domain.pfx -nocerts -nodes  -out domain_encrypted.key<br \/>\nopenssl rsa -in domain_encrypted.key -out domain.key<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So after you installed OpenSSL you can start it from it\u2019s Bin folder. I\u2019d like to put OpenSSL\\Bin in my path so I can start it from any folder. Fire up a command prompt and cd to the folder that contains your .pfx file. First type the first command to extract the private key:<\/p>\n<p>openssl [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6141"}],"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=6141"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6141\/revisions"}],"predecessor-version":[{"id":6144,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6141\/revisions\/6144"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}