Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does MD5 conversions work different in Java and in Android?

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.

like image 517
dinesh707 Avatar asked Jun 28 '26 18:06

dinesh707


1 Answers

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

like image 170
dinesh707 Avatar answered Jun 30 '26 07:06

dinesh707