因此,我希望将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==

最佳答案

将此传递给new()调用即可。

  hash_args=>{sha_size => 512}




{X-PBKDF2}HMACSHA2+512:AAAIAA:bW5lbW9uaWM=:WG00S/OSlPeYJ/HWeIPkVdQHpSXnpzG0Ixb+j70pbgDgdCAemPBLbjYBbcUtnfSS2dzMJng73eAlGSSnDi+dDQ==

10-06 11:37