Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transform a text string into an sha256 hash and then base64 encode it.
#!/bin/bash
#
# Takes in an e-mail address and answers back with the expected hash used
# for the AWS Cognito username field.
#
args=`getopt e: $*`
if [ $? != 0 ]; then
echo "Usage: ..."
exit 2
fi
set -- $args
for i
do
case "$i"
in
-e)
earg="$2"; shift;
shift;;
esac
done
if [ "X$earg" == "X" ]; then
echo "Usage: ..."
exit 3
else
echo -n $earg | shasum -a 256 | cut -d " " -f 1 | xxd -r -p | base64
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment