How to Extract the Private and Public Key From pfx File

Converting Private Key

// Convert Private RSA Key PEM 
openssl pkcs12 -in {pfx_file_name}.pfx -nocerts -nodes -passin pass:{password} | openssl rsa -out privkey.pem 

// Convert Private RSA Key to Private PEM 
openssl pkcs8 -topk8 -inform PEM -in privkey.pem -outform PEM -nocrypt > private.pem

Converting Public Certificate Pem

openssl pkcs12 -in {pfx_file_name}.pfx -clcerts -nokeys -passin pass:{password} -out publicCert.pem

Convert to Public Key

openssl pkcs12 -in {pfx_file_name}.pfx -clcerts -nokeys -passin pass:{password} | openssl x509 -pubkey -noout | ssh-keygen -f /dev/stdin -i -m PKCS8 > public_key

An alternative way

// Exports all keys
openssl pkcs12 -in {pfx_file_name}.pfx -nocerts -nodes -passin pass:{password} -out exported.key
// Export Private RSA Key PEM 
openssl rsa -in exported.key -out privkey.pem
// Convert Private RSA Key to Private PEM 
openssl pkcs8 -topk8 -inform PEM -in privkey.pem -outform PEM -nocrypt > private.pem

// Export Public key
openssl rsa -in exported.key -pubout -out publicCert.pem