Answer the question
In order to leave comments, you need to log in
How to generate a hash code based on a key in Python3?
In PHP, one function is enough to generate a hash code based on a key:
To try to figure this out in Python3, I had to pull out a lot of hair from my head.
Either use hashlib.sha256() or hmac.new - I still don't understand.
Question in title echo hash_hmac("sha256", "text", "signature");
Answer the question
In order to leave comments, you need to log in
>>> import hmac, hashlib
>>> res = hmac.new('signature', 'text', hashlib.sha256)
>>> res.hexdigest()
'3bd9ef87a8de4633a588904d24a64670905a3375687ae52e3daeba82dd702269'
>>> hmac.new(bytearray('signature','utf-8'), bytearray('text','utf-8'), hashlib.sha256).hexdigest()
'3bd9ef87a8de4633a588904d24a64670905a3375687ae52e3daeba82dd702269'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question