Hi, I need to create a HMAC in Python just the way the following Javascript code does:
var credentials = "admin:amin"; key="4545453030303743303134462035343733373432363420323031332D30382D33312031343A33353A3035" var shaObj = new jsSHA(credentials, "ASCII"); var hash = shaObj.getHMAC(key, "HEX", "HEX"); ---- in this case the hash is: 8347ce7126c1068aa183fbfdafe2c17a9cc86734 This javascript library can be tested here: http://caligatio.github.io/jsSHA/ So I'm trying to do the same in Python by: key="4545453030303743303134462035343733373432363420323031332D30382D33312031343A33353A303$ credentials = "admin:admin" hash = hmac.new(key, credentials, hashlib.sha1).hexdigest() ----- which gives me hash= 2c7e849a0eaa8cd0cc1120f6f156913755b674b6 Something's is wrong obviously. Maybe it has probably something to do with the encoding of the key or credentials but I'm lost on this. I tried to convert key to hex using the following function def toHex(s): lst = [] for ch in s: hv = hex(ord(ch)).replace('0x', '') if len(hv) == 1: hv = '0'+hv lst.append(hv) return reduce(lambda x,y:x+y, lst) But this didn't work either. Any help would be appreciated! -- http://mail.python.org/mailman/listinfo/python-list