Md5 from java to php
Posted: 10 Jan 2011, 07:52
I am trying to generate the same MD5 code as the md5() function in php.
Therefore when i use this code, the result is different:
Any help would be greatly appreciated.
Therefore when i use this code, the result is different:
Code: Select all
public static String md5(String input) throws NoSuchAlgorithmException {
String result = input;
if(input != null) {
MessageDigest md = MessageDigest.getInstance("MD5"); //or "SHA-1"
md.update(input.getBytes());
BigInteger hash = new BigInteger(1, md.digest());
result = hash.toString(16);
if ((result.length() % 2) != 0) {
result = "0" + result;
}
}
return result;
}