To verify if a private key matches the corresponding public key used in a certificate, one can use the trusty old OpenSSL.
Here are the steps (adjust the name of private key and certificate according to your needs ;))
Check the consistency of the private key:
openssl rsa -check -in private.key
Extract the public key from the certificate;
openssl x509 -in certificate.pem -noout -pubkey > public.key
Generate a public key from the private key:
openssl rsa -in private.key -pubout > private_pub.key
Compare the modulus values for the keys:
openssl rsa -pubin -in private_pub.key -noout -modulus
openssl rsa -pubin -in public.key -noout -modulus
If the modulus values are the same, it means that private key you have matches the public key used in the certificate.
Here's a quick guide on how to generate self-signed certificates using OpenSSL.
Top comments (0)