Search code examples
perlhashsha

hmac sha-256 in perl


What is the perl equivalent for this php code?

$hash = hash_hmac('sha256', $all , $secret);

I tried using the below code but in vain. The values are different.

use Digest::SHA;
$sha = Digest::SHA->new('sha256');
$sha->add($secret);
$sha->add($all);
$digest = $sha->hexdigest;

Regards, Pavan


Solution

  • Since my question was getting more views than I expected, I decided to answer it to help others with the same problem. I found the equivalent for it in PHP.

    use Digest::SHA qw(hmac_sha256_hex); 
    $digest=hmac_sha256_hex($all, $secret);
    

    Hope it helps.