@Test public void testMd5HexCase2() { String password = "meigaofei0926"; String runtimeValue = DigestUtils.md5Hex(password); String expectedValue = "0adb82835139278edb78d1e8c4548600"; Assertions.assertEquals(expectedValue, runtimeValue); }
public static String md5Hex(String password) { String md5 = ""; if ( password == null || password.isEmpty() ) { return ""; } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } md5 = sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return md5; }
DigestUtils { public static String md5Hex(String password) { String md5 = ""; if ( password == null || password.isEmpty() ) { return ""; } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } md5 = sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return md5; } }
DigestUtils { public static String md5Hex(String password) { String md5 = ""; if ( password == null || password.isEmpty() ) { return ""; } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } md5 = sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return md5; } private  DigestUtils(); }
DigestUtils { public static String md5Hex(String password) { String md5 = ""; if ( password == null || password.isEmpty() ) { return ""; } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } md5 = sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return md5; } private  DigestUtils(); static String md5Hex(String password); static String getGuid(); }
DigestUtils { public static String md5Hex(String password) { String md5 = ""; if ( password == null || password.isEmpty() ) { return ""; } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } md5 = sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return md5; } private  DigestUtils(); static String md5Hex(String password); static String getGuid();  }