** Problem solved. My input was altered on its way from the EditText to Java where I run the function. It was really obvious too. I feel really dumb. I'm really sorry for wasting everyone's time...
I'm trying to get android to encrypt a string using MD5 and have found that it does not match the results from md5 functions used in MySQL and PHP.
For example:
PHP/ MYSQL:
string: password
hash: 5f4dcc3b5aa765d61d8327deb882cf99
Android:
string: password
hash: bc4a7f3b32b2a85688a53c49df19cd95
I've searched for and looked at people on stackoverflow having the same problem but I still haven't found an answer. I've used numerous methods and tried changing character codes but it still never matches up.
Here's the function I currently have saved in my project (this doesn't work):
public static String md5(String input){
String result = input;
if(input != null) {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
md.update(input.getBytes());
BigInteger hash = new BigInteger(1, md.digest());
result = hash.toString(16);
if ((result.length() % 2) != 0) {
result = "0" + result;
}
}catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
return result;
}
Any help would be greatly appreciated.