PFX, P12, PKCS#12 — the same thing
.pfx and .p12 are two extensions for the same format. Unlike PEM it is binary, usually holds several objects at once and is always password-protected — even when the password is empty.
Building a PFX from PEM files
You typically have three files: the certificate, the private key and the chain of intermediates (with Let's Encrypt cert.pem, privkey.pem, chain.pem):
-certfileincludes the intermediates. Without it the server later lacks the chain — the most common reason for certificate verification failed after an import.-namebecomes the “friendly name” on Windows and makes it easier to pick in the certificate store later.- openssl prompts for the password. For scripts use
-passout file:path—-passout pass:…by contrast shows up in the process list and shell history.
If you have fullchain.pem (certificate and chain in one file), -in fullchain.pem without -certfile is enough.
When Windows rejects the PFX
OpenSSL 3 encrypts PFX files with AES-256 and SHA-256. Windows Server 2016, older Windows 10 builds and some Java and appliance versions do not understand this and report, misleadingly, “The password you entered is incorrect”. The fix is the old scheme:
Use it only for that case — for current systems the default is the better choice.
Taking a PFX apart
First look at what is inside (without writing anything):
Then extract the parts one by one:
-noenc is the name from OpenSSL 3 on; older versions only know -nodes, which still works in OpenSSL 3. Without the option openssl asks for a new password and writes the key encrypted — which a mail server cannot unlock at start-up, see Remove a private key passphrase.
Everything in one file, for HAProxy for instance: openssl pkcs12 -in mail.pfx -noenc -out complete.pem.
Bag attributes trip up some programs
When extracting, openssl writes lines such as Bag Attributes and friendlyName in front of each object. Most servers ignore them; a few parsers choke. Passing the files through once cleans them up:
Opening older PFX files with OpenSSL 3
PFX files from a Windows export or an old appliance are often encrypted with RC2-40. OpenSSL 3 moved that to the legacy provider and reports:
The file is not broken. Append -legacy to the command and it works: openssl pkcs12 -in old.pfx -legacy -noenc -out old.pem. A wrong password, by contrast, reads Mac verify error: invalid password?.
Afterwards
Whether key and certificate still belong together after the conversion and the chain is complete is covered in Check certificate and key.