Skip to content

Instantly share code, notes, and snippets.

@bjing
Last active November 13, 2021 12:42
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 bjing/235970447867059e19e2749e2ff0a47e to your computer and use it in GitHub Desktop.
Save bjing/235970447867059e19e2749e2ff0a47e to your computer and use it in GitHub Desktop.
alias urlencode='python -c "import urllib.parse, sys; print(urllib.parse.quote_plus(sys.argv[1])) if len(sys.argv) > 1 else print(urllib.parse.quote_plus(sys.stdin.readline()[0:-1]))"'
alias urldecode='python -c "import urllib.parse, sys; print(urllib.parse.unquote(sys.argv[1])) if len(sys.argv) > 1 else print(urllib.parse.unquote(sys.stdin.readline()[0:-1]))"'
# percent encode
urlencode $VALUE
# HMAC-SHA1 hashing
echo -n $VALUE | openssl dgst -sha1 -hmac $KEY
# Base64
echo -n $VALUE | base64
echo -n $VALUE | base64 --decode
#!/bin/bash
function hash_hmac {
digest="$1"
key="$2"
data="$3"
shift 3
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" "$@"
}
# digest could be sha1, sha256, md5 etc
hash_hmac "$1" "$2" "$3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment