Strings { public static String md5(String s) { try { final byte[] hash = MessageDigest.getInstance("MD5").digest(s.getBytes("UTF-8")); final StringBuilder hashString = new StringBuilder(); for (byte aHash : hash) { String hex = Integer.toHexString(aHash); if (hex.length() == 1) { hashString.append('0'); hashString.append(hex.charAt(hex.length() - 1)); } else { hashString.append(hex.substring(hex.length() - 2)); } } return hashString.toString(); } catch (Exception e) { throw new RuntimeException(e); } } private  Strings(); static String joinAnd(final String delimiter, final String lastDelimiter, final Collection<T> objs); static String joinAnd(final String delimiter, final String lastDelimiter, final T... objs); static String join(final String delimiter, final Collection<T> objs); static String join(final String delimiter, final T... objects); static String toString(InputStream input); static String toString(Reader input); static int copy(Reader input, Writer output); static long copyLarge(Reader input, Writer output); static String toString(final Object o); static String toString(final Object o, final String def); static boolean isEmpty(final Object o); static boolean notEmpty(final Object o); static String md5(String s); static String capitalize(String s); static boolean equals(Object a, Object b); static boolean equalsIgnoreCase(Object a, Object b); static String[] chunk(String str, int chunkSize); static String namedFormat(String str, Map<String, String> substitutions); static String namedFormat(String str, Object... nameValuePairs);  }
@Test public void shouldProduceCorrectMd5String() { final String s = "SiTrAax"; final String expected = "96843ce5846566b00b5311c8904addfd"; assertThat(Strings.md5(s), equalTo(expected)); }