Hashing { public static String generateMd5(String string) throws UnsupportedEncodingException, NoSuchAlgorithmException { byte[] bytesOfMessage = string.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] thedigest = md.digest(bytesOfMessage); StringBuffer sb = new StringBuffer(); for (int i = 0; i < thedigest.length; ++i) { sb.append(Integer.toHexString((thedigest[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } private  Hashing(); static String generateMd5(String string);  }
@Test public void shouldGenerateMd5WithLenghtAndIntegrity() throws Exception { String firstMd5 = Hashing.generateMd5("Hello World"); String secondMd5 = Hashing.generateMd5("Hello World2"); assertEquals(firstMd5.length(), secondMd5.length()); assertNotEquals(firstMd5, secondMd5); }