Article From:https://www.cnblogs.com/quxiangxiangtiange/p/9968259.html

/**
     * Get the MD5 encrypted string
     * @param str Plaintext
     * @return Encrypted string
     * @throws Exception
     */
    public static String getMD5(String str) throws Exception {
        /** Creating MD5 Encrypted Objects*/
        MessageDigest md5 = MessageDigest.getInstance(“MD5”);
        /** Encryption*/
        md5.update(str.getBytes());
        /** Get the encrypted byte array*/
        byte[] md5Bytes = md5.digest();
        String res = “”;
        for (int i = 0; i < md5Bytes.length; i++){
            int temp = md5Bytes[i] & 0xFF;
            if (temp <= 0XF){ // Conversion to hexadecimal is not enough two, plus zero before
                res += “0”;
            }
            res += Integer.toHexString(temp);
        }
        return res;
    }

From: https://zhidao.baidu.com/question/680167183405269052.html

Leave a Reply

Your email address will not be published. Required fields are marked *