Skip to content

Instantly share code, notes, and snippets.

@TranKovak
Last active December 15, 2020 12:46
Show Gist options
  • Save TranKovak/ea9c56fc5119059f4e15cb0ce0f4462c to your computer and use it in GitHub Desktop.
Save TranKovak/ea9c56fc5119059f4e15cb0ce0f4462c to your computer and use it in GitHub Desktop.
Convert pfx file to pem file #pfx #pem #cert

Conversion to a combined PEM file

To convert a PFX file to a PEM file that contains both the certificate and private key, the following command needs to be used:

# openssl pkcs12 -in filename.pfx -out cert.pem -nodes

Conversion to separate PEM files

We can extract the private key form a PFX to a PEM file with this command:

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

Exporting the certificate only:

# openssl pkcs12 -in filename.pfx -clcerts -nokeys -out cert.pem

Removing the password from the extracted private key:

# openssl rsa -in key.pem -out server.key

@acosonic
Copy link

Thanks for gist, adding
-chain added to openssl pkcs12 -in filename.pfx -clcerts -nokeys -out cert.pem exports full chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment