I’m trying to replicate the result of this site here with python hmac/hashlib.
I have a json object that I need to get the hash of:
{"event":"transaction:status_update","date":"2017-08-30T13:47:42+00:00","transactions":[{"id":"asdlfjasdf93","state":"COMPLETED","label":"Marked as review"},{"id":"fd09dfad8df9","state":"REVOKED","label":"Review complete."}]}
and below is the code I’m using to do so.
import hmac, hashlib
signature = hmac.new(
bytes('mykey', 'utf-8'),
msg = message.encode('utf-8'),
digestmod = hashlib.sha256
).hexdigest()
The issue I’m having is the site I linked probably does something with the string that python isn’t doing, or vice versa, and I can’t figure out how to format the string from the json. I’ve tried json.dumps(json_obj)
, str(json_obj)
, repr(json_obj)
. I can’t figure out what it is I’m missing, but the hash on the site and on python don’t match.
To be clear, this is a hash to be received through an external API and the site gave the correct hash, so I know I need to replicate this.
3