Extract .pem and .key from .pfx certificate for Swish

Share on:

Swish with PHP and curl requires original .pem and additionaly the extracted .key, which was a hassle to extract on Windows. To extract the key: import the .pem-cert into windows cert store on the machine that created the CSR and then export it to pfx with keys. Then do number two below.

1. .pfx to .pem

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

2. .pfx to .key

openssl pkcs12 -in filename.pfx -nocerts -out cert.key

3. .pfx to .pem without key

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

Källa: https://www.xolphin.com/support/Certificate_conversions/Convert_pfx_file_to_pem_file