MD5 in PHP and MD5 in Perl dont match up.
| From: | Steven Carr | Date: | Wed, 26 Mar 2003 15:20:28 +0000 |
| Subject: | MD5 in PHP and MD5 in Perl dont match up. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-141190@lists.php.net to get a copy of this message | ||
Hello All,
Im having trouble with compatibility between MD5 Digest in Perl and in
PHP. They dont give the same results.
Perl....
#!/usr/local/bin/perl
use strict;
use Digest::MD5 ();
my $to_be_hashed = "Cheese";
my ($hash) = Digest::MD5->md5_hex($to_be_hashed);
print "to_be_hashed : '$to_be_hashed' <P>\n";
print "hash : '$hash' <P>\n";
Gives....
to_be_hashed : 'Cheese' <P>
hash : '0a2a1678f4189d19a08396d9af56b4bb' <P>
In PHP..
$data = "Cheese\n";
print "Data: '$data' <P>\n";
$new_hash = md5($data);
print "RE HASH ' $new_hash ' <P>\n";
Gives....
Data: 'Cheese '
RE HASH ' c69f543f8f2ab31d5b8f148f55b56c56 '
I also tried a command line of echo -n 'Cheese' | md5sum
Which gives me the same hash as Perl. PHP seems to give me different
results.
Any Ideas what I am doing wrong? Has anyone else experienced this?
Many Thanks in advance,
Steven Carr.
----------
Steven Carr,
ISP Engineering,
steven.carr@ish.de