Android MD5 Encode getMd5(byte... values)

Here you can find the source of getMd5(byte... values)

Description

get Md

Declaration

public static String getMd5(byte... values) 

Method Source Code

//package com.java2s;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class Main {
    public static String getMd5(byte... values) {
        String cacheKey;/*from   w w w.ja  v a 2s.com*/
        try {
            final MessageDigest mDigest = MessageDigest.getInstance("MD5");
            mDigest.update(values);
            cacheKey = bytesToHexString(mDigest.digest());
        } catch (NoSuchAlgorithmException e) {
            cacheKey = String.valueOf(Arrays.hashCode(values));
        }
        return cacheKey;
    }

    private static String bytesToHexString(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte aByte : bytes) {
            String hex = Integer.toHexString(0xFF & aByte);
            if (hex.length() == 1) {
                sb.append('0');
            }
            sb.append(hex);
        }
        return sb.toString();
    }
}

Related

  1. md5File(File file)
  2. md5Hex(String str)
  3. computeHashMD5(final String text)
  4. getMD5String(File file)
  5. getMD5String(String str)
  6. checkDicMD5(String dicFile, final byte[] expected)
  7. MD5(String md5)
  8. getMD5Str(String str)
  9. MD5(String text)