Check If a Certificate Matches Its Private Key
A certificate and a private key are two halves of one key pair. The certificate carries the public key, the server holds the private key, and the TLS handshake only works when the two belong together. When they do not, the web server usually refuses to start, or starts and serves a certificate that cannot complete a handshake.
You can verify the match without any special tooling: compare the public key of the certificate with the public key derived from the private key. If the two hashes are identical, the pair matches.
Certificate and private key: the three checks
# 1. Public key hash of the certificate
openssl x509 -in certificate.crt -noout -pubkey | openssl sha256
# 2. Public key hash derived from the private key
openssl pkey -in private.key -pubout | openssl sha256
# 3. Public key hash inside a CSR
openssl req -in request.csr -noout -pubkey | openssl sha256
Run all three on the same host. Two identical lines mean those two files belong together. This works for RSA and for ECDSA keys, which is why it is safer than comparing moduli, a method that only applies to RSA.
What the errors mean
| Where | Message | What it means |
|---|---|---|
| Nginx | SSL_CTX_use_PrivateKey() failed (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch) | The key file and the certificate file are from different issuances. Nginx refuses to start. |
| Apache | SSL Library Error: ... key does not match certificate | Same cause. Apache logs it and may still serve the wrong pair if another vhost is loaded. |
| IIS | A specified logon session does not exist, or the certificate cannot be used | The .pfx import failed, or the certificate was imported without its private key. |
| cURL | SSL certificate problem: unable to get local issuer certificate | A different problem: the chain is incomplete, not the key pair. |
Why a certificate and its private key stop matching
- Two certificates were issued for the same domain and the old key was paired with the new certificate, or the other way round.
- A renewal generated a fresh key pair and only the certificate was copied to the server.
- A ZIP bundle was unpacked and the key from one folder was copied next to the certificate from another.
- A hosting panel regenerated the CSR and key after the certificate had already been issued.
The fastest safe fix is to reissue: generate a fresh key and CSR, complete validation, and install the three files from the same download. Patching a mismatched pair by guessing which file is stale costs more time than issuing a new certificate.
Check the CSR before you submit it
A CSR contains the public key and the names you asked for. Compare its hash with the certificate after issuance, and read its subject and SAN list to confirm nothing is missing. A wildcard for *.example.com does not cover example.com, so both must appear in the SAN list if both must work.
openssl req -in request.csr -noout -text | grep -A1 'Subject Alternative Name'
Formats, and why the key is in one file or not
| Format | Extensions | Contains private key | Typical use |
|---|---|---|---|
| PEM (Base64) | pem, crt, cer, key | In a separate .key file | Nginx, Apache, cPanel, Docker, Linux |
| PKCS#12 | pfx, p12 | Yes, password protected | Windows IIS, Azure, Tomcat, Exchange |
| DER (binary) | der, cer | No | Java keystores, embedded devices |
| PKCS#7 | p7b | No, chain only | Windows certificate stores |
Converting PEM to PFX for Windows is a single command, and the resulting file must contain the leaf, the key and the intermediate chain: openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt -certfile ca_bundle.crt. If the import later fails in IIS, the usual cause is a missing intermediate.
Check without uploading the real key
A private key is the one secret that should never be pasted into a website you do not control. If you want a quick check without the terminal, use Key Matcher with a throwaway key, or compare the certificate's public key against the server's live handshake with the SSL Checker. The checker reads only what the server already sends to every visitor.
For format conversion, the PEM to PFX converter bundles a certificate, key and chain into a password-protected archive. Do that locally or on a tool you trust, and delete the downloaded archive after the import.
Related reading: generating a private key and CSR, free SSL vs self-signed SSL and SSL for agencies managing many sites.
Frequently Asked Questions
Can I reuse the same CSR when renewing?
You can, and you probably should not. A new key pair on each renewal limits the damage if an old backup leaked, and on a free certificate it costs nothing.
Does a wildcard certificate cover the root domain?
No. *.example.com covers www.example.com and any other single label, not example.com. Put both names in the SAN list.
Why does IIS need a PFX instead of a CRT and KEY?
IIS imports the certificate, private key and chain together into the Windows certificate store, and PKCS#12 is the container that holds all three under one password.
Is comparing moduli still valid?
Only for RSA keys. The public-key hash comparison in the first section works for RSA and ECDSA, so use that instead.
✅ 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.