1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
   | public class MD5 { 	 	public static final String getMd5(String str) { 		 		char hexDigits[] = { '5', '0', '5', '6', '2', '9', '6', '2', '5', 'q', 'b', 'l', 'e', 's', 's', 'y' };
  		char strchar[]; 		 		byte strbyte[]; 		strbyte = str.getBytes(); 		 		MessageDigest instance; 		try { 			 			instance = MessageDigest.getInstance("MD5"); 			 			instance.update(strbyte); 			 			byte[] digest = instance.digest(); 			int j = digest.length; 			int k = 0; 			strchar = new char[j * 2]; 			 			for (int i = 0; i < j; i++) { 				byte byte0 = digest[i]; 				strchar[k++] = hexDigits[byte0 >>> 4 & 0xf]; 				strchar[k++] = hexDigits[byte0 & 0xf]; 			} 			 			return new String(strchar);
  		} catch (NoSuchAlgorithmException e) { 			e.printStackTrace(); 			return null; 		}
  	} 	public static void main(String[] args) { 		System.out.println(MD5.getMd5("Milkyaw")); 	} }
 
  |