Skip to content

Instantly share code, notes, and snippets.

@niedbalski
Created November 9, 2012 21:08
Show Gist options
  • Save niedbalski/4048240 to your computer and use it in GitHub Desktop.
Save niedbalski/4048240 to your computer and use it in GitHub Desktop.
hmac-encrypt-request
from Crypto.Hash import HMAC
from Crypto.Hash import SHA
import hashlib
import datetime
class Auth:
@classmethod
def sign(cls, method, c_type, body, uri, key=None):
sign = "%s\n%s\n%s\n%s\n%s\n" % (method, c_type,
hashlib.md5(body).hexdigest(),
datetime.datetime.utcnow()
.strftime('%Y-%m-%d-%H:%M'), uri)
return cls.crypt(sign, key)
@classmethod
def crypt(cls, value, key):
return HMAC.new(key, value, SHA).hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment