Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Last active August 29, 2015 14:00
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 gene1wood/11064617 to your computer and use it in GitHub Desktop.
Save gene1wood/11064617 to your computer and use it in GitHub Desktop.
Determine the modulus of a certificate, key or certificate request and output it for the purposes of comparing them to confirm they match
#!/bin/bash
if grep -- ' PRIVATE KEY-' "$1" >/dev/null; then
modulus="`openssl rsa -noout -modulus -in "$1" | md5sum | awk '{print $1}'`"
elif grep -- '-BEGIN CERTIFICATE REQUEST-' "$1" >/dev/null; then
modulus="`openssl req -noout -modulus -in "$1" | md5sum | awk '{print $1}'`"
elif grep -- '-BEGIN CERTIFICATE-' "$1" >/dev/null; then
modulus="`openssl x509 -noout -modulus -in "$1" | md5sum | awk '{print $1}'`"
else
modulus="unknown"
fi
#if [ "${1##*.}" = "key" ]; then
# modulus="`openssl rsa -noout -modulus -in $1 | md5sum | awk '{print $1}'`"
#elif [ "${1##*.}" = "crt" ]; then
# modulus="`openssl x509 -noout -modulus -in $1 | md5sum | awk '{print $1}'`"
#elif [ "${1##*.}" = "csr" ]; then
# modulus="`openssl req -noout -modulus -in $1 | md5sum | awk '{print $1}'`"
#else
# modulus="unknown"
#fi
echo "$modulus $1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment