Last active
December 27, 2015 14:09
-
-
Save wonderb0lt/7338974 to your computer and use it in GitHub Desktop.
A cheap example of HMAC in python.
This file contains 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
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