Skip to content

Instantly share code, notes, and snippets.

@v0lkan
Last active September 3, 2022 00:22
Show Gist options
  • Save v0lkan/4805adff88cbb61464da to your computer and use it in GitHub Desktop.
Save v0lkan/4805adff88cbb61464da to your computer and use it in GitHub Desktop.
salted sha
#!/usr/bin/env bash
# Warning: SHA1 is considered cryptographically broken.
# Do not use it for very sensitive stuff.
# It’s “good enough” for not-so-sensitive stuff.
die () {
echo >&2 "$@"
echo "Usage: ssha.sh username password"
exit 1
}
[ "$#" -eq 2 ] || die "2 arguments required, $# provided."
USERNAME="$1"
PASSWORD="$2"
SALT="$(openssl rand -base64 3)"
SHA1=$(printf "$PASSWORD$SALT" | openssl dgst -binary -sha1 | sed 's#$#'"$SALT"'#' | base64)
printf "$USERNAME:{SSHA}$SHA1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment