The accepted answer is the correct command, I just want to add one additional thing, when extracting the key if you leave the PEM password("Enter PEM pass phrase:"
) blank then the complete key will not be extracted but only the localKeyID
will be extracted. To get the complete key you must specify a PEM password whem running the following command.
Please note that when it comes to Import password, you can specify the actual password for "Enter Import Password:"
or can leave this password blank:
openssl pkcs12 -in yourP12File.pfx -nocerts -out privateKey.pem