Erlang calculating HMAC-SHA1 example? -
any examples or libraries caculate hmac-sha1 in erlang?
i tried crypto module, apparently doesn't match exactly. examples?
to expand on previous answer, here hmac module in python using sha-1 algorithm key 'hello' , message 'world':
>>> import hashlib >>> import hmac >>> hmac.hmac(key='hello', msg='world', digestmod=hashlib.sha1).hexdigest() '8a3a84bcd0d0065e97f175d370447c7d02e00973'
here's equivalent in erlang. i'd use more efficient method convert binary mac hex digest in typical code, used 1 brevity:
1> crypto:start(). ok 2> <<mac:160/integer>> = crypto:hmac(sha, <<"hello">>, <<"world">>). <<138,58,132,188,208,208,6,94,151,241,117,211,112,68,124, 125,2,224,9,115>> 3> lists:flatten(io_lib:format("~40.16.0b", [mac])). "8a3a84bcd0d0065e97f175d370447c7d02e00973"
Comments
Post a Comment