MD5加密测试_java类
使用MD5对字符进行加密处理。 public MD5Test(String inStr1) { this.inStr = inStr1; try { this.mad5 = MessageDigest.getInstance("MD5"); } catch (Exception ex) { System.out.println(ex.toString()); // ex.printStackTrace(); } } public String compute() { char[] charArray = this.inStr.toCharArray(); byte[] byteArray = new byte[charArray.length]; for (int i = 0; i < charArray.length; i++) byteArray[i] = (byte) charArray[i]; byte[] md5Byte = this.mad5.digest(byteArray); StringBuffer hexValue = new StringBuffer(); for (int i = 0; i < md5Byte.length; i++) { int val = ((int) md5Byte[i]) & 0xff; if (val < 16) hexValue.append("0"); hexValue.append(Integer.toHexString(val)); } return hexValue.toString(); }