为什么 Digest::SHA 得出的哈希值与 RFC 4868 中显示的哈希值不同?
我正在尝试编写一些 Perl 来与其他语言(即 Java)中的哈希函数进行交互操作。我们找到了可能是正确的来源,RFC 4868其中包括一些测试键和字符串及其散列值。我正在使用以下代码片段,但无法让 Perl 得出相同的结果。我只能假设我使用得不正确——有人能指出我正确的方向吗?
use Digest::SHA qw(hmac_sha512_hex);
my $key = '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b';
my $value = '4869205468657265';
print hmac_sha512_hex($value, $key);
输出是“4ef7 ... 5d40”,尽管 RFC 4868(和我同胞的 Java 实现)返回“87aa ... 6854”
I'm trying to write some Perl to inter operate with hash functions in other languages, namely Java at this point. We have found what is presumably a correct source, RFC 4868 which includes some test keys & strings along with their hashed values. I'm using the following snippet, and can't get Perl to come up with the same result. I can only assume that I'm using it incorrectly—can anyone point me in the right direction?
use Digest::SHA qw(hmac_sha512_hex);
my $key = '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b';
my $value = '4869205468657265';
print hmac_sha512_hex($value, $key);
The output is '4ef7 ... 5d40', though RFC 4868 (and my compatriot's Java implementation) returns '87aa ... 6854'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
引用
RFC:
PS 将
'0x'
添加到字符串不会使其成为二进制,它会使其以'0'
和'x';-)
Gives
Quoting RFC:
P.S. Adding
'0x'
to the string doesn't make it binary, it makes it start with'0'
and'x'
;-)