MD5 String Util : MD5.xml « Security « Android






MD5 String Util

 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

 class MD5StringUtil
{
    private static final MessageDigest digest;

    static
    {
        try
        {
            digest = MessageDigest.getInstance("MD5");
        }
        catch (NoSuchAlgorithmException e)
        {
            throw new RuntimeException(e);
        }
    }

    public static String md5StringFor(String s)
    {
        final byte[] hash = digest.digest(s.getBytes());
        final StringBuilder builder = new StringBuilder();
        for (byte b : hash)
        {
            builder.append(Integer.toString(b & 0xFF, 16));    
        }
        return builder.toString();
    }
}

   
  








Related examples in the same category

1.Md5 sum
2.MD5 hash generator.
3.md5 sum and hmac Sha1 Digest
4.Create Md5 Checksum
5.MD5 Hash
6.Download from URL and MD5 check
7.Md5 Hash and MessageDigest
8.Md5 String