Home arrow static arrow Java Programming [Archive] - MD5 PHP Java
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - MD5 PHP Java
This topic has 5 replies on 1 page.

Posts:79
Registered: 9/27/03
MD5 PHP Java  
Jul 31, 2004 6:09 AM



 
Hello!

Daoes anyone has any idea why Java implementation of MD5 (MessageDigest MD5 ) returns different hash than PHP implementation ?

I need to compare those two...

Thanx.
 

Posts:47
Registered: 4/1/03
Re: MD5 PHP Java  
Jul 31, 2004 6:48 AM (reply 1 of 5)



 
that's impossible,MD5 is a standard arithmetic

how did you wrote ?
 

Posts:2,909
Registered: 13.8.2003
Re: MD5 PHP Java  
Aug 1, 2004 10:41 PM (reply 2 of 5)



 
Make sure you're not adding garbage characters (linefeeds etc.) when you're calculating the checksum.
 

Posts:3,055
Registered: 18/06/98
Re: MD5 PHP Java  
Aug 2, 2004 5:59 AM (reply 3 of 5)



 
Probably you're forgetting that Java MessageDigest functions return byte arrays, that must be converted in hexadecimal strings, to match the PHP function. Another thing that can go wrong is that there is the "byte encoding" problem.

Check if your MD5 Java function, when applied to the string "Hello, world!", produces the MD5 hash shown below. (The PHP function has to produce the same result).

( Hexadecimal dump of the string "Hello, world!" )

0000 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 Hello, world!


(MD5 value)

MD5 = 6cd3556deb0da54bca060b4c39479839
 

Posts:447
Registered: 3/8/01
Re: MD5 PHP Java  
Aug 2, 2004 6:52 AM (reply 4 of 5)



 
Make sure that both use characters in the same encoding. Java chars are 16-bit (unicode), but I'm not sure about PHP. You can convert a Java string to a byte[] with some other encoding though, using the java.nio.charset.Charset class.
 

Posts:3,055
Registered: 18/06/98
Re: MD5 PHP Java  
Aug 2, 2004 7:19 AM (reply 5 of 5)



 
If you search the Cryptography forum you could find a function that duplicates the MD5 functionality of PHP.
 
This topic has 5 replies on 1 page.