i have a javascript password coder
md5 = hex_hmac_md5(secret, password)
How can i emulate this in python – ive tried md5 but that is not the same value
i got my md5 javascript code from this website:
(md5.js)
He states the use is as follows:
In many uses of hashes you end up
wanting to combine a key with some
data. It isn’t so bad to do this by
simple concatenation, but HMAC is
specifically designed for this use.
The usage is:hash = hex_hmac_md5(“key”, “data”);
The HMAC result is also available
base-64 encoded or as a binary string,
using b64_hmac_* or str_hmac_*.Some other hash libraries have the
arguments the other way round. If the
JavaScript HMAC doesn’t match the
value your server library generates,
try swapping the order.
I have tried some python like this:
> def md5_test(secret, password):
>
> return md5(secret+password).hexdigest()
Can anyone tell me what the code should be in python to get the same value?
Thanks
That’s what Python’s
hmacmodule is for, don’t use the MD5 function directly.Also take a look at how HMAC is implemented (e.g. on Wikipedia).