简单的md5加密:
1 package com.util; 2 3 import java.security.MessageDigest; 4 import java.security.NoSuchAlgorithmException; 5 6 public class MD5 { 7 public static String Md5(String plainText) { 8 String md5=null; 9 try { 10 MessageDigest md = MessageDigest.getInstance("MD5"); 11 md.update(plainText.getBytes()); 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 md5 = buf.toString().substring(8, 24); 24 25 } catch (NoSuchAlgorithmException e) { 26 e.printStackTrace(); 27 } 28 return md5; 29 } 30 }