0

I'm sorry but I need help for building an Android app that will have a function to generate MD5 hash from a file and a textfile. Can you help me, I don't very understand on Android development, but my teacher keep pushing me (sorry about that).

Thank you so much for your help. Hari (Indonesia)

  • You can find the answer at http://stackoverflow.com/questions/304268/getting-a-files-md5-checksum-in-java – upenpat Apr 15 '14 at 11:02

1 Answers1

0

MD5 Hash function:

public static final String md5(final String s) 
    {
        try 
        {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();

            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) 
            {
                String h = Integer.toHexString(0xFF & messageDigest[i]);
                while (h.length() < 2)
                    h = "0" + h;
                hexString.append(h);
            }
            return hexString.toString();
        }

        catch (NoSuchAlgorithmException e) 
        {
            e.printStackTrace();
        }
        return "";
    }
KRP
  • 294
  • 7
  • 22
  • what should I do to input these script to android app in a button? I'm sorry before. And, I must make a button to open file that will be generated of its MD5 hash. How? – user3535589 Apr 19 '14 at 11:20