Last active
November 13, 2021 12:42
-
-
Save bjing/235970447867059e19e2749e2ff0a47e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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