Skip to content

Instantly share code, notes, and snippets.

@lsloan
Created June 27, 2016 16:54
Show Gist options
  • Save lsloan/cc7a122a9f99d856e3299cac723ae9d0 to your computer and use it in GitHub Desktop.
Save lsloan/cc7a122a9f99d856e3299cac723ae9d0 to your computer and use it in GitHub Desktop.
A (Bash) shell function for creating digest values.
#!/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