文件名称:MD5加密测试_java类
文件大小:736B
文件格式:ZIP
更新时间:2012-12-01 08:05:48
MDT TEST,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(); }
【文件预览】:
MD5Test.java