@Test public void testMD5Util() { byte[] input = {49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 49}; String output = MD5Util.makeMD5(input); String expect = "499351bfa5f412772850df0c87a965f5"; assertEquals(expect, output); }
public static String makeMD5(byte [] data) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (NoSuchAlgorithmException e) { System.out.println(e); } return result; }
MD5Util { public static String makeMD5(byte [] data) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (NoSuchAlgorithmException e) { System.out.println(e); } return result; } }
MD5Util { public static String makeMD5(byte [] data) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (NoSuchAlgorithmException e) { System.out.println(e); } return result; }  }
MD5Util { public static String makeMD5(byte [] data) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (NoSuchAlgorithmException e) { System.out.println(e); } return result; }  static String makeMD5(byte [] data); }
MD5Util { public static String makeMD5(byte [] data) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (NoSuchAlgorithmException e) { System.out.println(e); } return result; }  static String makeMD5(byte [] data);  }