Skip to content

Instantly share code, notes, and snippets.

Created September 14, 2017 15:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joyrexus/946ea887e2d21b950e20972c2f4f7139 to your computer and use it in GitHub Desktop.
make hmac cli
A little script for generating HMACs.
For example ...
> ./ secret foo
import sys, hashlib, base64, hmac
def make_hmac(secret, body):
Calculate the HMAC value of the given request body and secret
as per Shopify's documentation for Webhook requests.
digest =, body, hashlib.sha256).digest()
return base64.b64encode(digest)
def is_valid(HMAC, secret, body):
Check if the HMAC matches that calculated from the given request
body and secret.
return HMAC == make_hmac(secret, body)
if __name__ == '__main__':
[secret, body] = sys.argv[1:3]
print make_hmac(secret, body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment