This guide provides an overview of common certificate file types – .p7b, .cer, and .pfx – and demonstrates how to manage them using OpenSSL. You'll learn how to perform various conversions and exports, which is essential for system administration, web server configuration, and secure communications.
| File Type | Format | Contents | Typical Use |
|---|---|---|---|
.p7b |
PKCS#7 (Base64 or DER) | Certificate chain; no private key | Distributing certificate chains |
.cer |
PEM (Base64) or DER (binary) | Single certificate or certificate chain | Installing on web servers, clients |
.pfx |
PKCS#12 (binary, password‑protected) | Certificate(s) with corresponding private key | Import/export of certificates and private keys, typically on Windows |
OpenSSL is a versatile command‑line tool that can handle various cryptographic functions, including converting and managing certificate files. In this guide, we cover common tasks such as:
.p7b file to PEM format.pfx file.cer file between DER and PEM formatsA .p7b file (PKCS#7) usually contains a certificate chain but no private key. To extract the certificates in PEM format, use the following OpenSSL command:
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.pem
This command reads the certificate.p7b file and outputs the contained certificates to certificate.pem in PEM format.
A .pfx file (PKCS#12) bundles certificates with their private keys. To extract the certificate and private key in PEM format, use these commands.
openssl pkcs12 -in certificate.pfx -nocerts -nodes -out privatekey.pem
This command extracts the private key from certificate.pfx and writes it to privatekey.pem. The -nodes flag ensures the private key is not encrypted in the output.
openssl pkcs12 -in certificate.pfx -clcerts -nokeys -out cert.pem
This command extracts only the certificate (without private keys) from the .pfx file and writes it to cert.pem.
openssl pkcs12 -in certificate.pfx -nokeys -out chain.pem
If your .pfx file contains intermediate certificates, this command will extract the full chain into chain.pem.
A .cer file can be in either DER (binary) or PEM (Base64) format. To convert between these formats, use the following commands.
openssl x509 -inform DER -in certificate.cer -out certificate.pem
This converts a DER‑encoded certificate (certificate.cer) to PEM format.
openssl x509 -outform DER -in certificate.pem -out certificate.der
This converts a PEM‑encoded certificate (certificate.pem) to DER format, saved as certificate.der.
openssl x509 -in certificate.pem -text -noout
openssl x509 -noout -modulus -in certificate.pem | openssl md5
openssl rsa -noout -modulus -in privatekey.pem | openssl md5
Compare the MD5 hashes; they should match.
.pfx files, you’ll be prompted for a password. You can also add encryption to output files by omitting the -nodes option.