SSL Certificate – Extract crt and key from pfx cert file
How to Convert a PFX Certificate to PEM and Extract the CRT File
In this article, I will show you how to convert a PFX certificate to PEM format and extract the CRT file using OpenSSL. Follow these simple steps to complete the operation.
1. Extract the Private Key from the PFX File
First, we need to extract the private key from the PFX file. Use the following command:
1 |
openssl pkcs12 -in your_certificate.pfx -nocerts -out private_key.key |
This command will prompt you to enter the password for the PFX file and then set a password to protect the extracted private key.
2. Extract the Certificate (CRT) from the PFX File
Next, we extract the CRT certificate from the PFX file with the following command:
1 |
openssl pkcs12 -in your_certificate.pfx -clcerts -nokeys -out certificate.crt |
This command will prompt you to enter the password for the PFX file.
3. (Optional) Remove the Password from the Private Key
If you want to remove the password from the private key, you can use the following command:
1 |
openssl rsa -in private_key.key -out private_key_nopass.key |
This command will prompt you to enter the password you set to protect the private key during extraction.
Complete Example
Here is a complete example of all commands with passwords:
1 2 3 4 5 6 7 8 9 10 |
# Extract the private key (you will be prompted to enter the PFX file password and to set a password for the private key) openssl pkcs12 -in your_certificate.pfx -nocerts -out private_key.key # Extract the CRT certificate (you will be prompted to enter the PFX file password) openssl pkcs12 -in your_certificate.pfx -clcerts -nokeys -out certificate.crt # (Optional) Remove the password from the private key (you will be prompted to enter the password set for the private key) openssl rsa -in private_key.key -out private_key_nopass.key |
By following these steps, you will be able to successfully extract the private key and certificate from the PFX file, even if it is password protected. If you need further details or assistance, feel free to ask in the comments!