Skip to content

Instantly share code, notes, and snippets.

@dmendiza
Created July 19, 2015 17:08
Show Gist options
  • Save dmendiza/3846d876db0d491416c0 to your computer and use it in GitHub Desktop.
Save dmendiza/3846d876db0d491416c0 to your computer and use it in GitHub Desktop.
# import hmac library
import hmac
# configure a key
HMAC_KEY = 'O\x8cNd\x16E\xb1U\x1b\x0b\xe8\t\xd8\xab\xbcI'
# change signing function to use hmac
ctx = hmac.new(KEY, digestmod=hashlib.sha256)
ctx.update(request.args["data"])
digest = ctx.hexdigest()
# change verification function to use hmac
ctx = hmac.new(KEY, digestmod=hashlib.sha256)
ctx.update(request.args["data"])
computed_digest = ctx.hexdigest().decode('utf8')
if hmac.compare_digest(request.args["digest"], computed_digest):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment