Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract private key from pfx file using openssl? [closed]

I was looking for this private key to add ssl certificate in Softlayer's "Add Certificate" wizard and to use it further with Local Load Balancer.

I googled and tried following openssl command:

openssl pkcs12 -in filename.pfx -nocerts -out key.pem 

But I ended up with invalid "RSA PRIVATE KEY". Please help.

like image 389
Sharad Pratap Singh Avatar asked May 06 '13 11:05

Sharad Pratap Singh


People also ask

How do I get PEM from PFX?

Navigate to Traffic Management, Select the SSL node. Click the Import PKCS#12 link. Specify a file name you want for the PEM certificate in the Output File Name field. Click Browse and select the PFX certificate that you want to convert to PEM format.

How do I export a private key from a certificate?

Go to: Certificates > Personal > Certificates. Right-click on the certificate you wish to export and go to All Tasks and hit Export. Hit Next on the Certificate Export Wizard to begin the process. Select “Yes, export the private key” and hit next.


1 Answers

Your command is correct, and gives you the encrypted private key in PKCS#8 format. If you need the unencrypted private key, just add the -nodes option:

openssl pkcs12 -in filename.pfx -nocerts -nodes -out key.pem 

If you need the private key in old RSA format, you should convert the given key with the openssl pkcs8 command:

openssl pkcs8 -in key.pem -out rsakey.pem 

See the documentation for details:

  • https://www.openssl.org/docs/man1.1.0/apps/pkcs12.html
  • https://www.openssl.org/docs/man1.1.0/apps/pkcs8.html
like image 61
user1516873 Avatar answered Sep 19 '22 00:09

user1516873