package cn.i2edu.dubbing_lib.audioUtils;

import java.security.MessageDigest;

public class MD5Util {

    public static String getMD5Str(String src) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(src.getBytes());
            return toHexString(messageDigest.digest());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private static String toHexString(byte[] b) {
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (byte aB : b) {
            sb.append(Digit[(aB & 0xf0) >>> 4]);
            sb.append(Digit[aB & 0x0f]);
        }
        return sb.toString();
    }

    private static final char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

}