1 /** 2 * md5签名 3 * @param plainText 要签名的字符串 4 * @param enc 要编译的格式 gbk;utf-8 5 * @return 6 */ 7 public static String MD5(String plainText,String enc) { 8 String re_md5 = new String(); 9 try { 10 MessageDigest md = MessageDigest.getInstance("MD5"); 11 md.update(plainText.getBytes(enc)); 12 byte b[] = md.digest(); 13 int i; 14 StringBuffer buf = new StringBuffer(""); 15 for (int offset = 0; offset < b.length; offset++) { 16 i = b[offset]; 17 if (i < 0) 18 i += 256; 19 if (i < 16) 20 buf.append("0"); 21 buf.append(Integer.toHexString(i)); 22 } 23 re_md5 = buf.toString(); 24 } catch (Exception e) { 25 e.printStackTrace(); 26 } 27 return re_md5; 28 29 30 }
时间: 2024-11-08 21:55:11