Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53357
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-08-31 07:24 -0700 |
| Message-ID | <3479e08e-d435-492b-b2a0-a1c18678f6ab@googlegroups.com> (permalink) |
| Subject | HMAC encription issue |
| From | sergio7654@gmail.com |
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!
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
HMAC encription issue sergio7654@gmail.com - 2013-08-31 07:24 -0700
Re: HMAC encription issue Roy Smith <roy@panix.com> - 2013-08-31 10:39 -0400
Re: HMAC encription issue Sergio Sanchez <sergio7654@gmail.com> - 2013-08-31 07:48 -0700
Re: HMAC encription issue Roy Smith <roy@panix.com> - 2013-08-31 11:01 -0400
Re: HMAC encription issue Sergio Sanchez <sergio7654@gmail.com> - 2013-08-31 08:16 -0700
csiph-web