HowTo: verify SSL private key matches SSL certificate

Posted over 6 years ago. Visible to the public. Linked content.

When receiving a new SSL-Certificate for an existing SSL-key it should be checked that they match cryptographically.
Maybe the customer accidentally created a new key and certificate and sent us just the certificate.

It's also possible that the certificate chain is in the wrong order. Make sure that the server certificate is the first. This is also necessary for nginx.

It is recommended to pipe the public keys of both files through an hashing algorithm, to easier identify differences. Instead of comparing the modulus the same syntax applies to RSA and ECDSA certificates:

openssl pkey -pubout -in server.key | openssl sha1

openssl req -pubkey -noout -in server.csr | openssl sha1

openssl x509 -pubkey -noout -in server.crt | openssl sha1

If they match, the resulting hash will be identical:

$ openssl pkey -pubout -in | openssl sha1
(stdin)= 559bd107c03237891a468f2c3dcbb0a47035e797

$ openssl x509 -pubkey -noout -in | openssl sha1
(stdin)= 559bd107c03237891a468f2c3dcbb0a47035e797


You can also use the graphical tool XCA.

Marius Schuller
Last edit
Over 1 year ago
Andreas Vöst
About this deck
We are makandra and do test-driven, agile Ruby on Rails software development.