MD5转换成数字

如题,uuid生成32位字符串,想把这个字符串 变成数字

 /**
     * md5转数值型
     * 这个算法返回值理想长度是16,因为md.length = 16
     */
    public static String ConvertNum(String s) {

        if(StringUtil.isEmpty(s)){
            return null;
        }
        // 这里根据MD5时间的值更换16进制abc的大小写
        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        try {
            byte[] btInput = s.getBytes();
            //获得MD5摘要算法的 MessageDigest 对象
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            //使用指定的字节更新摘要
            mdInst.update(btInput);
            //获得密文
            byte[] md = mdInst.digest();
            char str[] = new char[md.length];
            int k = 0;
            for (int i = 0; i < md.length; i++) {
                byte byte0 = md[i];
                //只取高位
                str[k++] = hexDigits[(byte0 >>> 4 & 0xf) % 10];
            }
            return new String(str);
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
原文地址:https://www.cnblogs.com/zeussbook/p/15380584.html