Created
November 9, 2012 21:08
-
-
Save niedbalski/4048240 to your computer and use it in GitHub Desktop.
hmac-encrypt-request
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
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