Skip to content

Instantly share code, notes, and snippets.

@tauzen
Last active March 26, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tauzen/e5013f78f62f4ddd45f8 to your computer and use it in GitHub Desktop.
Save tauzen/e5013f78f62f4ddd45f8 to your computer and use it in GitHub Desktop.
openssl keys and cert generation, signed digest generation, verification of signed digest
# Creating a RSA private key
$ openssl genrsa -out rsaprivkey.pem 1024
# Creating a cert file from priv key
$ openssl req -new -x509 -key rsaprivkey.pem -out rsacert.pem
# Converting from PEM to DER
$ openssl x509 -outform der -in rsacert.pem -out rsacert.der
# Convertin from DER to PEM
$ openssl x509 -inform der -in rsacert.der -out rsacert.pem
# Signing a digest of a file
$ openssl dgst -sha1 -sign rsaprivkey.pem -out file.sig file
# Extracting pub key from cert
$ openssl x509 -pubkey -noout -in rsacert.pem > pubkey.pem
# Verifyig the signature
$ openssl dgst -sha1 -verify pubkey.pem -signature file.sig file
# Getting the fingerpring of the cert, from pem cert
$ openssl x509 -in rsacert.pem -fingerprint -noout
SHA1 Fingerprint=B4:4B:81:58:DA:9A:17:1E:42:54:83:ED:3E:F8:BD:0B:8E:7C:9B:F9
# Getting the fingerprint or the cert, from der (cer)
$ openssl dgst -sha1 rsacert.der
SHA1(rsacert.der)= b44b8158da9a171e425483ed3ef8bd0b8e7c9bf9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment