Friday, November 26, 2010

Extract SSL Certificate and Private Key from PFX file

In this tutorial I will show you how to extract SSL certificate and key from PFX file and also how to remove a password from a private SSL key.

The certificate extraction can be done with a tool called Open SSL that you may install from the Linux server repository, Also you can use the Windows version: OpenSSL for Windows.



# To export the private key from the pfx file:
openssl pkcs12 -in cert.pfx -nocerts -out key.key

# To export the certificate from the pfx file:
openssl pkcs12 -in cert.pfx -clcerts -nokeys -out cert.pem

# And now remove the key password:
openssl rsa -in key.pem -out key_with_no_pw.key


Probably from the comments, you have guessed already the purpose of each line, but I will explain these lines briefly

The first line will export the private key from the windows certificate and since PFX key is always exported with a password, you will be prompted to enter one. So you must have it.

The second line will export certificate from the PFX file.

The Third line will remove the key password



C:\OpenSSL\bin>openssl pkcs12 -in cert.pfx -nocerts -out key.pem
Enter Import Password: *****
MAC verified OK
Enter PEM pass phrase: **********
Verifying - Enter PEM pass phrase: **********


The above example will show you how to extract the private key from .pfx file



Leave your comment below

No comments:

Post a Comment