package com.donkingliang.imageselector.utils; import java.security.MessageDigest; /** * @Author teach liang * @Description MD5工具类 * @Date 2019/1/2 */ public class MD5Utils { private static final String HEX_DIGITS[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; public static String md5(String s) { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bytes = md.digest(s.getBytes("utf-8")); return toHex(bytes); } catch (Exception e) { e.printStackTrace(); } return null; } private static String toHex(byte[] bytes) { StringBuilder ret = new StringBuilder(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]); ret.append(HEX_DIGITS[bytes[i] & 0x0f]); } return ret.toString(); } }