Anyone know why sha1sum and the following script which uses Digest::SHA1 would generate different output? Am I misusing Digest::SHA1 in some weird way?
Here's the runtime:
$ hashit "foo"
foo -X- 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
$ echo "foo" | sha1sum -
f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 -
Code:
#!/usr/bin/perl -w
use Digest;
sub hash_msg {
my $hashed = Digest->new("SHA-1");
$hashed->add($_[0]);
return $hashed->hexdigest;
}
foreach $arg (@ARGV) {
chomp $arg;
print $arg, " -X- ", hash_msg($arg), "\n";
}
Here's the runtime:
$ hashit "foo"
foo -X- 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
$ echo "foo" | sha1sum -
f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 -