Question : MD5 in java like PHP's md5()

Hello,

I am creating a browser based game using java. On registration, the password is converted to md5 using php's md5() function, and than the Java applet will check in the database if the password is correct. It is a bit more advanced, it md5s the users ip and some other things too.

Simply, I want a function that reutrns exact same value as the php md5() function.

I tried this:
http://www.spiration.co.uk/post/1199/Java%20md5%20example%20with%20MessageDigest
,but that skips some zeros.

Thanks!

Answer : MD5 in java like PHP's md5()

Try the following
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
    public static String asString(byte[] data) {
	String result = null;
	try {
	    MessageDigest md = MessageDigest.getInstance("MD5");
	    result = new BigInteger(md.digest(data)).toString(16);
	}
	catch(NoSuchAlgorithmException e){
	    e.printStackTrace();	
	}

	return result;
    }
Random Solutions  
 
programming4us programming4us