所以我希望使用SHA-512和PBKDF2来实现Bitcoin BIP-039。我已经设法确定SHA-512属于SHA2但是当我指定它作为散列函数时,即使使用64字节输出,它仍然报告为使用SHA-256。我错过了什么吗?我尝试将+512添加到hash_class但是没有用。
#!/usr/bin/perl
#
use Crypt::PBKDF2;
my $sentence="Hellothere";
my $salt="mnemonic";
my $pbkdf2 = Crypt::PBKDF2->new(
hash_class => 'HMACSHA2', #
iterations => 2048, #
output_len => 64, #
);
my $hash = $pbkdf2->generate($sentence,$salt);
print "$hash\n";
给出
{X-PBKDF2}HMACSHA2+256:AAAIAA:bW5lbW9uaWM=:NLw67sZbhQYsPhrEYm9e5ruslS6/ivK1vDfICtCN07rb7RuBkQxAoZIyTG7sTmsob30JwoP64Fvzpjx6Cqc+KQ==
答案 0 :(得分:5)
将此传递给new()调用有效。
hash_args=>{sha_size => 512}
{X-PBKDF2}HMACSHA2+512:AAAIAA:bW5lbW9uaWM=:WG00S/OSlPeYJ/HWeIPkVdQHpSXnpzG0Ixb+j70pbgDgdCAemPBLbjYBbcUtnfSS2dzMJng73eAlGSSnDi+dDQ==
答案 1 :(得分:0)
use Crypt::KeyDerivation 'pbkdf2';
my $data = pbkdf2("Hellothere", "mnemonic", 2048, 'SHA512', 64);
print unpack("H*", $data), "\n";