Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

MD5 compatibility in PHP

by strredwolf (Chaplain)
on Feb 10, 2002 at 23:50 UTC ( [id://144531]=perlquestion: print w/replies, xml ) Need Help??

strredwolf has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone check to see if PHP's 'md5()' function is compatible with MD5 module's 'md5->hash()'? Just would like to know before I execute a Perl script that converts UBB (Infopop crudware) to phpBB on a shell.

--
$Stalag99{"URL"}="http://stalag99.keenspace.com";

Replies are listed 'Best First'.
Re: MD5 compatibility in PHP
by gav^ (Curate) on Feb 11, 2002 at 01:16 UTC
    A quick test:

    Perl

    use Digest::MD5 qw(md5_hex); print "1: foo => ", md5_hex("foo"), "\n"; print "2: bar => ", md5_hex("bar"), "\n"; print "3: 123 => ", md5_hex(123), "\n"; print "4: empty => ", md5_hex(""), "\n";

    Output

    1: foo => acbd18db4cc2f85cedef654fccc4a4d8 2: bar => 37b51d194a7513e45b56f6524f2d51f2 3: 123 => 202cb962ac59075b964b07152d234b70 4: empty => d41d8cd98f00b204e9800998ecf8427e

    PHP

    <? echo "1: foo => ", md5("foo"), "\n"; echo "2: bar => ", md5("bar"), "\n"; echo "3: 123 => ", md5(123), "\n"; echo "4: empty => ", md5(""), "\n"; ?>

    Output

    1: foo => acbd18db4cc2f85cedef654fccc4a4d8 2: bar => 37b51d194a7513e45b56f6524f2d51f2 3: 123 => 202cb962ac59075b964b07152d234b70 4: empty => d41d8cd98f00b204e9800998ecf8427e

    gav^

Re: MD5 compatibility in PHP
by Ryszard (Priest) on Feb 11, 2002 at 00:50 UTC
    Given that MD5 is actually a ratified algorithm, I would say yes.

    There however may be differences in the implementation of each algorithm that cause the output to be different. If this is the case, you'll have to proove which one is incorrect against a known correct hash.

    Another difference may be in the output method you choose, for example:

  • $digest = md5($data);
  • $digest = md5_hex($data);
  • $digest = md5_base64($data);
    Taken from the perldoc Digest::MD5

    Fundimentally, if the algorithm has been composed following the rfc you will have no worries.

Re: MD5 compatibility in PHP
by jepri (Parson) on Feb 11, 2002 at 00:51 UTC
    You're usually on the ball, which is why I'm a little confused that you didn't just run the corresponding hash functions on an arbitrary piece of text, say the string: "Some test characters for the hash function" and compare the results.

    Also run them on the empty string "" just to be sure.

    It used to be that such functions would use the underlying system libraries, but now languages tend to use their own library functions. Nonetheless if it says 'MD5' I'd guess there's a high chance they will be the same function. There's probably a standard somewhere.

    Update: My thinking, which may not be clear to casual bystanders, is that if two functions both claiming to be MD5 hashing functions return the same values for the null value and any other representative value then they are probably the same function. I keep thinking that I want the kernel (or nullspace) and a basis but that's not going to work because the functions are many-to-one. Wait four months till I finish my crypto course and then I'll be able to tell you :D

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://144531]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-19 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found