Skip to content

Instantly share code, notes, and snippets.

@BennettSmith
Created November 11, 2016 20:15
Show Gist options
  • Save BennettSmith/20a98bfaa5b4f0797dfa66706f7765c3 to your computer and use it in GitHub Desktop.
Save BennettSmith/20a98bfaa5b4f0797dfa66706f7765c3 to your computer and use it in GitHub Desktop.
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