MD5加密中文請求引數亂碼問題解決
阿新 • • 發佈:2019-01-04
public static String md5(String str,String charsetName) { String result = ""; MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); md5.update(str.getBytes(charsetName)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } byteb[] = md5.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); returnresult; }