Java MD5 Byte Array md5Hex(byte data[])

Here you can find the source of md5Hex(byte data[])

Description

md Hex

License

Open Source License

Declaration

public static String md5Hex(byte data[]) 

Method Source Code


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

public class Main {
    private static final String HEX_CHARS = "0123456789abcdef";

    public static String md5Hex(byte data[]) {
        return toHexString(md5(data));
    }/*from  w w  w .  ja  v a  2 s.c om*/

    public static String md5Hex(String data) {
        return toHexString(md5(data));
    }

    public static String toHexString(byte b[]) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < b.length; i++) {
            sb.append(HEX_CHARS.charAt(b[i] >>> 4 & 0xf));
            sb.append(HEX_CHARS.charAt(b[i] & 0xf));
        }

        return sb.toString();
    }

    public static byte[] md5(byte data[]) {
        return getDigest().digest(data);
    }

    public static byte[] md5(String data) {
        return md5(data.getBytes());
    }

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

    }
}

Related

  1. md5Byte(String encryptStr)
  2. MD5Bytes(byte[] src)
  3. md5Bytes(String message)
  4. md5Bytes(String s)
  5. md5Digest(byte[] bytes)
  6. md5Hex(byte[] data)
  7. md5key(byte[] key)
  8. md5P(final ByteBuffer bb)
  9. MD5Raw(byte[] src)