1 public class MD5 { 2 3 public static String getMD5(String content) { 4 try { 5 MessageDigest digest = MessageDigest.getInstance("MD5"); 6 digest.update(content.getBytes()); 7 return getHashString(digest); 8 9 } catch (NoSuchAlgorithmException e) { 10 e.printStackTrace(); 11 } 12 return null; 13 } 14 15 private static String getHashString(MessageDigest digest) { 16 StringBuilder builder = new StringBuilder(); 17 for (byte b : digest.digest()) { 18 builder.append(Integer.toHexString((b >> 4) & 0xf)); 19 builder.append(Integer.toHexString(b & 0xf)); 20 } 21 return builder.toString(); 22 } 23 }