Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Digest::SHA1 and sha1sum disagreements

Status
Not open for further replies.

craigmcl

IS-IT--Management
Jun 26, 2002
8
US
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?

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 -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top