Skip to content

Instantly share code, notes, and snippets.

@Yoshyn
Last active October 22, 2021 15:15
Show Gist options
  • Save Yoshyn/796c3b2e9ede42ef7a5f443d24d10394 to your computer and use it in GitHub Desktop.
Save Yoshyn/796c3b2e9ede42ef7a5f443d24d10394 to your computer and use it in GitHub Desktop.
Verify a certificat (crt) and a private key

Let's check

Check the certificat openssl x509 -in certificate.crt -text -noout

Compare the certificat & the private key; This :

openssl x509 -modulus -noout -in mycomp.com.crt | openssl md5

Should return the same as :

openssl rsa -modulus -noout -in mycomp.com.key | openssl md5

Let's test it (in this case it's rsa encryption) :

1 - First : retrieve the public key in the certificat

openssl x509 -in mycomp.com.crt -pubkey -noout > mycomp.com-pub.pem

2 - encrypt a string

openssl rsautl -encrypt -inkey mycomp.com-pub.pem -pubin -in <(echo "my string to encrypt") -out /tmp/data.enc cat /tmp/data.enc

3 - Check that file is well encrypted

openssl rsautl -decrypt -inkey mycomp.com.key -in /tmp/data.enc rm /tmp/data.enc

Links :

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