Вопрос

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)

Это было полезно?

Решение

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 "";
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top