KeyMaker { public String getMd5(String msg) { MessageDigest md; try { md = getMessageDigest(); byte[] hash = md.digest(msg.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(2 * hash.length); for (byte b : hash) { sb.append(String.format("%02x", b & 0xff)); } return sb.toString(); } catch (NoSuchAlgorithmException ex) { logger.error("Fail to get MD5 of String "+msg, ex); } return null; }  String getMd5(String msg);  }
@Test public void testGetMd5() { System.out.println("getMd5"); String msg = "sentenceforhashing"; String expResult = "f3c1cdbb34896be04a270098f6772e96"; String result = instance.getMd5(msg); assertThat(result).isEqualTo(expResult); }