Convert PFX to PEM (and back)

Windows wants PFX, nginx wants PEM, Java wants PKCS#12. Here is how to switch between the formats and which pitfalls OpenSSL 3 brought.

The formats

Without OpenSSL: convert in the browser

Drop the PFX file into the certificate converter and enter the password. Certificate, chain and key can then be downloaded separately or as a bundle. The other way round, the converter takes certificate and key as PEM and builds a PFX, completing missing intermediates automatically. Everything runs in your browser.

PFX → PEM with OpenSSL

# everything in one file (key unencrypted)
openssl pkcs12 -in file.pfx -out all.pem -nodes

# server certificate only
openssl pkcs12 -in file.pfx -clcerts -nokeys -out server.crt

# intermediates only
openssl pkcs12 -in file.pfx -cacerts -nokeys -out chain.crt

# private key only
openssl pkcs12 -in file.pfx -nocerts -nodes -out server.key

“unsupported” error with OpenSSL 3

error:0308010C:digital envelope routines::unsupported

Older PFX files are encrypted with RC2 or 3DES. OpenSSL 3 only loads these algorithms in legacy mode. The fix is the -legacy switch:

openssl pkcs12 -legacy -in old.pfx -out all.pem -nodes

PEM → PFX with OpenSSL

openssl pkcs12 -export -out server.pfx \
  -inkey server.key -in server.crt -certfile chain.crt

Windows says “The password you entered is incorrect”

OpenSSL 3 encrypts PFX with AES-256 by default. Windows Server 2016 and older cannot open that and report a wrong password although it is correct. Files created with 3DES work everywhere:

openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt -certfile chain.crt \
  -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1

The certificate converter creates PFX files with 3DES from the start and reads both AES and older RC2 files.

Which format for which server?

FAQ

I forgot the PFX password. What now?

A PFX cannot be opened without the password. If the certificate is still installed on a Windows server and the key is marked exportable, export it again there with a new password. Otherwise only a reissue helps.

Why are the intermediates missing after conversion?

Some PFX files only contain the server certificate. The converter fetches missing intermediates automatically via the AIA entry in the certificate.

Is .cer the same as .crt?

Both are just extensions for certificates. The content can be PEM (text) or DER (binary). Open the file in a text editor: if it starts with -----BEGIN CERTIFICATE-----, it is PEM.