Created
June 27, 2016 16:54
-
-
Save lsloan/cc7a122a9f99d856e3299cac723ae9d0 to your computer and use it in GitHub Desktop.
A (Bash) shell function for creating digest values.
This file contains hidden or 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/sh -- | |
function hash_hmac { | |
digest="$1" | |
data="$2" | |
key="$3" | |
shift 3 | |
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" "$@" | |
} | |
# hex output by default | |
hash_hmac sha1 'value' 'key' | |
# raw output by adding the "-binary" flag | |
hash_hmac sha1 'value' 'key' -binary | base64 | |
# other algos also work | |
hash_hmac md5 'value' 'key' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment