I have a use case where i have to generate md5 hash of a JSON object and compare the hashes in the server and the browser.
The browser client generates hash and then asks the server for the hash of the same resource[ which happens to be a JSON object], and compares both the hashes to decide what to do next.
For server i am using Python and browser client is in Javascript.
For me the hashes generated in both cases do not match. Here's my code:
Python:
>>> import hashlib
>>> import json
>>> a = {"candidate" : 5, "data": 1}
>>> a = json.dumps(a, sort_keys = True).encode("utf-8")
>>> hashlib.md5(a).hexdigest()
>>> 12db79ee4a76db2f4fc48624140adc7e
JS: I am using md5 for hashing in browser
> var hash = require("md5")
> var data = {"candidate":5, "data":1}
> data = JSON.stringify(data)
> md5(data)
> 92e99f0a99ad2a3b5e02f717a2fb83c2
What is it that i am doing wrong?
md5is not secure. Better to use something modern likesha384orsha256.