Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hmac sha-256 in perl

Tags:

hash

perl

sha

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

like image 682
Pavan Avatar asked Jul 06 '12 14:07

Pavan


1 Answers

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.

like image 90
Pavan Avatar answered Oct 22 '22 16:10

Pavan