Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Created July 5, 2016 01:46
Show Gist options
  • Save magnetikonline/fbdb26fcb34ca5038c03507cbdfdb534 to your computer and use it in GitHub Desktop.
Save magnetikonline/fbdb26fcb34ca5038c03507cbdfdb534 to your computer and use it in GitHub Desktop.
SSL certificate - compare modulus of certificate vs. private key for equality.

SSL certificate - compare certificate vs. private key

Or to put it another way...

Does this certificate I have actually work with this private key I have?

Where server.crt is your certificate and server.key is your private key:

$ certMod=$(openssl x509 -text -noout -modulus -in server.crt | grep "Modulus=") && \
	keyMod=$(openssl rsa -text -noout -modulus -in server.key | grep "Modulus=") && \
	[[ $certMod == $keyMod ]] && echo "Equal"

If certificate works with private key - you should be greeted with a response of Equal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment