This one works:
import java.security.MessageDigest;
import java.security.Security;
import java.security.NoSuchAlgorithmException;
import java.io.UnsupportedEncodingException;
public class HelloWorld{
public static String ConvertToHash(String password)
{
try {
MessageDigest ms = MessageDigest.getInstance("MD5");
byte[] pass = password.getBytes();
byte[] byteData = ms.digest(password.getBytes("UTF-8"));
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
return null;
} catch (UnsupportedEncodingException e) {
return null;
}
}
public static void main(String []args){
System.out.println(ConvertToHash("password"));
System.out.println(ConvertToHash("password"));
}
}