我观察到每次执行脚本时,给定数据和密钥的 HMAC SHA512 输出都会发生变化。
首先,我举一个输出不变的脚本示例:
#! /usr/bin/perl
use Digest::SHA qw(hmac_sha512_hex);
use warnings;
$data="test";
$key="20202020";
print hmac_sha512_hex($data,$key),"\n";
我运行此脚本两次并获得相同的输出:
perl test.pl
457a1ff378f11880defaa91675de4633d1f1e69712b5dccd2f86612224b825b4461a9215a37cce53
8e7f5de43a6900867667b9361af38df32fc58e54d7ce9a02
perl test.pl
457a1ff378f11880defaa91675de4633d1f1e69712b5dccd2f86612224b825b4461a9215a37cce53
8e7f5de43a6900867667b9361af38df32fc58e54d7ce9a02
现在我修改脚本中的数据变量如下:
#! /usr/bin/perl
use Digest::SHA qw(hmac_sha512_hex);
use warnings;
$data={'method' => 'test', 'value' => 21};
$key="20202020";
print hmac_sha512_hex($data,$key),"\n";
现在每次运行脚本时输出都不同:
perl test.pl
cb1a40ba7a7f52da39dc0a3f130399dfbecb5249946057fd19887b72a58701f28452f6e663153bb6
85a4b86f9d427de4af5904801e11cb6fcbc272344605c2a9
perl test.pl
73dd1678a4e7f29f8032a65cbe979248b3e41cd6ed7aa81e5b214b8b6232af1e7a6683412b8532b7
187313d2c2a96c7e5009a9362690f355028b56ca319825e4
我该如何纠正?