public String generateKey(String title, String userName){
char[] hexDigits = "0123456789abcdef".toCharArray();
String source;
String MD5 = null;
byte[] digest = null;
source = title + "balh" + userName ;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
digest = md.digest(source.getBytes("UTF-16"));
StringBuilder sb = new StringBuilder(32);
for (byte b : digest)
{
sb.append(hexDigits[(b >> 4) & 0x0f]);
sb.append(hexDigits[b & 0x0f]);
}
System.out.println("Gened KEY ===="+sb.toString());
return sb.toString();
} catch (Exception e) {
}
return "";
}
I use the same code to generate key in android, and in Servlet. But I get different results. What am I doing wrong? Or if those are not compatible then how to make them.
I used the following method in both server and android client. It worked. But don’t know what’s the problem I had.
http://mobile.dzone.com/news/android-snippet-making-md5