Skip to content

Instantly share code, notes, and snippets.

@nickgravel
Last active October 4, 2015 16:45
Show Gist options
  • Save nickgravel/b6e7a0f1cb35df245118 to your computer and use it in GitHub Desktop.
Save nickgravel/b6e7a0f1cb35df245118 to your computer and use it in GitHub Desktop.
Generate a OpenSSL Private Key and CSR with SHA256 Signature for 2048 SSL Certs
#!/bin/bash
if [ -n "$1" ]
then
FILENAME=$1
else
echo "Please specify a filename. e.g. ./gencsr www.example.com" >&2
exit 1
fi
# Generate key
echo "Generating private key..."
openssl genrsa -out $FILENAME.key 2048
# Create CSR
echo "Creating CSR..."
openssl req -out $FILENAME.csr -key $FILENAME.key -new -sha256
# check that the signature is correct, should display: Signature Algorithm: sha256WithRSAEncryption
echo "Verifying signature algorithm..."
openssl req -in $FILENAME.csr -noout -text | grep sha256WithRSAEncryption
if [ $? -eq 0 ]
then
echo "Successfully created private key and CSR"
exit 0
else
echo "Could not verify signature algorithm." >&2
rm $FILENAME.key
rm $FILENAME.csr
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment