Convert P7B to PEM: PKCS#7 Certificate Bundle
A .p7b file is a PKCS#7 bundle. It carries a certificate and usually its chain, but never the private key. CAs often send it for Windows and Java servers. Nginx, Apache and most Linux tools want PEM instead. The conversion is one OpenSSL command, but the details of encoding and order decide whether the result works. This guide uses the OpenSSL documentation for the pkcs7 command. If you are unsure what the other file types are, read the certificate file types guide first.
What a P7B contains
The OpenSSL documentation says openssl pkcs7 processes PKCS#7 files and that it only understands PKCS#7 version 1.5 as defined in RFC 2315. It cannot parse CMS. The -print_certs option prints any certificates or CRLs contained in the file, and -quiet with it prints only the PEM-encoded certificates.
| Part | In a P7B? |
|---|---|
| Your server certificate | Yes |
| Intermediate certificates | Usually |
| Root certificate | Sometimes |
| Private key | Never |
The command
If the P7B is a text file with -----BEGIN PKCS7----- at the top, it is PEM encoded, which is the default input format:
openssl pkcs7 -in bundle.p7b -print_certs -out certs.pem
If it is binary, tell OpenSSL with -inform DER:
openssl pkcs7 -inform DER -in bundle.p7b \
-print_certs -out certs.pem
The output file contains each certificate preceded by a line with its subject and issuer. Those lines are readable text that most servers ignore, but you can strip them. Add -quiet, as the documentation describes, to print only the PEM blocks:
openssl pkcs7 -in bundle.p7b -print_certs -quiet -out certs.pem
Use -text instead if you want full details of each certificate.
Split the result into leaf and chain
Open certs.pem. Each block starts with -----BEGIN CERTIFICATE-----. The order in the file is not guaranteed to be leaf first. Check each block:
openssl x509 -in certs.pem -noout -subject -issuer
That prints only the first block. To inspect all of them, copy each block into its own file, or run:
openssl crl2pkcs7 -nocrl -certfile certs.pem |
openssl pkcs7 -print_certs -noout
Your server certificate is the one whose subject is your domain. The others are intermediates. A certificate whose subject and issuer are identical is a root, and you do not need to send it.
Build a full chain file
Servers want the leaf first, followed by the intermediates:
cat server.pem intermediate.pem > fullchain.pem
Nginx takes this file as ssl_certificate, and your private key goes in ssl_certificate_key. Apache 2.4.8 or later takes it as SSLCertificateFile. The reasoning is in what fullchain.pem is. Check the key matches the leaf with the key matcher.
Verify the chain before you deploy
Do not install the new file on a live server until you have checked it. Verify the leaf against the intermediates offline:
openssl verify -untrusted intermediate.pem server.pem
You should see server.pem: OK. If OpenSSL says it cannot get the local issuer certificate, an intermediate is missing from the bundle. Ask the CA for the right chain, or download it from the CA's repository, and check its subject against the issuer shown for your leaf. A missing intermediate causes errors in some browsers and apps but not others, which makes it hard to spot. See what an SSL certificate chain is.
After deployment, test from outside with openssl s_client -connect example.com:443 -showcerts and count the certificates the server sends. Two certificates, the leaf and one intermediate, is the usual shape for a Let's Encrypt style chain.
Common errors
- **unable to load PKCS7 object.** The input encoding is wrong. Try
-inform DER, or the opposite. - **The output has no private key.** That is correct. Use the key file you made with the CSR. See what a CSR is.
- **Wrong order in the chain.** Some clients fail when the intermediate comes first. Rebuild with the leaf first.
- **A CMS file, not PKCS#7.** The
pkcs7command cannot read it, per the documentation.
Going the other way
If you need a P7B from PEM files, the usual route is:
openssl crl2pkcs7 -nocrl -certfile fullchain.pem -out bundle.p7b
For a PFX, which does include the key, see how to convert PEM to PFX. For the reverse of that, PFX to PEM. The SSL converter handles these without commands. Then verify the live chain with the free SSL chain checker.
Source: OpenSSL documentation, openssl-pkcs7(1).
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.