Skip to content

Instantly share code, notes, and snippets.

@wonderb0lt
Last active December 27, 2015 14:09
Show Gist options
  • Save wonderb0lt/7338974 to your computer and use it in GitHub Desktop.
Save wonderb0lt/7338974 to your computer and use it in GitHub Desktop.
A cheap example of HMAC in python.
import base64
import urllib
import hashlib
import hmac
def sign_url(url, key='test'):
h = hmac.new(bytes(key), url, digestmod=hashlib.sha1)
hmacs = urllib.quote_plus(base64.b64encode(h.digest()))
return url + '&hmac=' + hmacs
# Usage:
# python sign.py url [key]
# (i.e. the url parameter must always be present)
import sys
print sign_url(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment