2011-08-30 6 views
2
난 당신이 다이제스트가되지 않습니다 진수를 볼 수있는 펄이

파이썬 상응하는

# 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 

을 무엇을 파이썬에서 재현 할 필요가

을 hmac_sha1_hex 같은 ... 내가 파이썬 펄 코드를 재현 할 수있는 방법?

감사합니다.

+1

'펄 -MDigest :: HMAC_SHA1 = hmac_sha1_hex -E '말 ("문자열 1", "문자열 2")가 hmac_sha1_hex' 펄에서 훨씬 더 볼 것 세계 – yko

답변

9

Python의 HMAC 생성자는 키와 메시지를 반대 순서로 사용합니다. Python의 hmac이 먼저 키를 가져오고 Perl의 Digest::HMAC은 키를 두 번째로 가져옵니다.

python -c 'import sha; import hmac; print hmac.new("string2", "string1", sha).hexdigest()' 
25afd2da17e81972b535d15ebae464e291fb3635 

는 잘 펄 예를 일치 :