Skip to content

Instantly share code, notes, and snippets.

@freyes
Forked from niedbalski/auth.py
Created January 6, 2016 21:28
Show Gist options
  • Save freyes/2f39bac59f11f6e0a5d9 to your computer and use it in GitHub Desktop.
Save freyes/2f39bac59f11f6e0a5d9 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