1 package cn.fraudmetrix.octopus.horai.biz.utils; 2 3 import java.security.MessageDigest; 4 import java.security.NoSuchAlgorithmException; 5 6 public ...
1 package cn.fraudmetrix.octopus.horai.biz.utils; 2 3 import java.security.MessageDigest; 4 import java.security.NoSuchAlgorithmException; 5 6 public class Md5Util { 7 //靜態方法,便於作為工具類 8 public static String getMd5(String plainText) throws NoSuchAlgorithmException { 9 MessageDigest md = MessageDigest.getInstance("MD5"); 10 md.update(plainText.getBytes()); 11 byte b[] = md.digest(); 12 int i; 13 StringBuffer buf = new StringBuffer(""); 14 for (int offset = 0; offset < b.length; offset++) { 15 i = b[offset]; 16 if (i < 0) 17 i += 256; 18 if (i < 16) 19 buf.append("0"); 20 buf.append(Integer.toHexString(i)); 21 } 22 //32位加密 23 return buf.toString(); 24 // 16位的加密 25 //return buf.toString().substring(8, 24); 26 } 27 }View Code