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;
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM