Skip to content

Converting PKCS#12 (.pfx) to PEM with OpenSSL

Overview

This guide will show you how to convert a PKCS#12 file to PEM format using OpenSSL.

Conversion

Extract private and public key to PEM (no encryption/password):

Terminal window
openssl pkcs12 -in certificate.pfx -out certificate.pem -nodes

Extract public key to PEM:

Terminal window
openssl pkcs12 -in certificate.pfx -clcerts -nokeys -out certificate.pem -nodes

Extract private key to PEM:

Terminal window
openssl pkcs12 -in certificate.pfx -nocerts -out key.pem

Extract private key to PEM (no encryption/password):

Terminal window
openssl pkcs12 -in certificate.pfx -nocerts -out key.pem -nodes

Other useful commands

Remove password from private key (from PEM):

Terminal window
openssl rsa -in key.pem -out key-out.pem

Concatinate public and private key:

Terminal window
cat certificate.pem key.pem > combined.pem