Skip to content

Instantly share code, notes, and snippets.

@philippeoz
Last active May 30, 2019 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philippeoz/da1318d7951007f45eacf4ed7bb95278 to your computer and use it in GitHub Desktop.
Save philippeoz/da1318d7951007f45eacf4ed7bb95278 to your computer and use it in GitHub Desktop.
Simple python implementation of CryptoJS hmac functions
# import hashlib <~ import to use as parameter 'hashlib_type'
import hmac
def make_signature(message, key, hashlib_type):
"""
works like CryptoJS.Hmac*
js:
>> CryptoJS.HmacSHA1(message, key).toString()
py:
>> make_signature(message, key, hashlib.sha1)
"""
key = bytes(key, 'utf-8')
message = bytes(message, 'utf-8')
hashed = hmac.new(key, message, hashlib_type)
return hashed.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment