i need to reproduce in python what perl does
# perl
perl -e'use Digest::HMAC_SHA1 qw(hmac_sha1_hex); my $hmac = hmac_sha1_hex("string1", "string2"); print $hmac . "\n";'
25afd2da17e81972b535d15ebae464e291fb3635
#python
python -c 'import sha; import hmac; print hmac.new("string1", "string2", sha).hexdigest()'
3953fa89b3809b8963b514999b2d27a7cdaacc77
as you can see the hex digest is not the same … how can I reproduce the perl code in python ?
thanks !
Python’s HMAC constructor just takes the key and the message in the opposite order — Python’s
hmactakes the key first, Perl’sDigest::HMACtakes the key second.Matches your Perl example just fine 🙂