Python hmac (sha1) calculation -


i trying calculate hmac-sha1 value in python, results don't match standard tool using reference (openssl):

python

k = "ffffffffffffffffffffffffffffffff" m = "ffffffffffffffffffffffffffffffff" key = k.decode("hex") msg = m.decode("hex") print xlong(hmac.new(key, msg=msg, digestmod=hashlib.sha1).digest()) 

result: 801271609151602865551107406598369208989784139177

openssl

echo -n ‘ffffffffffffffffffffffffffffffff’ | xxd -r -p | openssl dgst -sha1 -mac hmac -macopt hexkey:ffffffffffffffffffffffffffffffff 

result: 8c5a42f91479bfbaed8dd538db8c4a76b44ee5a9

try using binascii.hexlify() on hmac:

>>> binascii import hexlify >>> print hexlify(hmac.new(key, msg=msg, digestmod=hashlib.sha1).digest()) 8c5a42f91479bfbaed8dd538db8c4a76b44ee5a9 

or may use str.encode('hex'):

>>> print hmac.new(key, msg=msg, digestmod=hashlib.sha1).digest().encode('hex') 8c5a42f91479bfbaed8dd538db8c4a76b44ee5a9 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -