Last active
May 30, 2019 17:06
-
-
Save philippeoz/da1318d7951007f45eacf4ed7bb95278 to your computer and use it in GitHub Desktop.
Simple python implementation of CryptoJS hmac functions
This file contains hidden or 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 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