My experience in perl is lacking. But, from what I read online and have seen googling this problem; perl's md5, sha1, sha256 ... should be returning the same hash as php or any other language, but aren't.
is there something I'm misunderstanding or missing?
Perl Code: (v5.14.2)
use Digest::SHA 'sha1_hex';
print Digest::SHA->sha1_hex("test");
# outputs e2412033b6d0070b931d01b0d1783b937608eb7f
PHP Code: (v5.4)
echo sha1("test");
//outputs: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
Your program should look like:
use Digest::SHA 'sha1_hex';
print sha1_hex("test");
or
use Digest::SHA;
print Digest::SHA::sha1_hex("test"); # note ::
When you call Digest::SHA->sha1_hex("test");
, you're using so called "indirect object" notation, which is equivalent to sha1_hex("Digest::SHA", "test")
· That's why you get different hash:
use Digest::SHA 'sha1_hex';
say sha1_hex("Digest::SHAtest")
# -> e2412033b6d0070b931d01b0d1783b937608eb7f