---恢復內容開始---
/** * 對字符串md5加密 * * @param str * @return * @throws Exception */ public String getMD5Str(String str) throws Exception { try { // 生成一個MD5加密計算摘要 MessageDigest md = MessageDigest.getInstance("MD5"); // 計算md5函數 md.update(str.getBytes()); // digest()最后確定返回md5 hash值,返回值為8為字符串。因為md5 hash值是16位的hex值,實際上就是8位的字符 // BigInteger函數則將8位的字符串轉換成16位hex值,用字符串來表示;得到字符串形式的hash值 return new BigInteger(1, md.digest()).toString(16); } catch (Exception e) { throw new Exception("MD5加密出現錯誤,"+e.toString()); } }
---恢復內容結束---