AuthHashGenerator { String generateHash(String timestamp, String publicKey, String privateKey) throws MarvelApiException { try { String value = timestamp + privateKey + publicKey; MessageDigest md5Encoder = MessageDigest.getInstance("MD5"); byte[] md5Bytes = md5Encoder.digest(value.getBytes()); StringBuilder md5 = new StringBuilder(); for (int i = 0; i < md5Bytes.length; ++i) { md5.append(Integer.toHexString((md5Bytes[i] & 0xFF) | 0x100).substring(1, 3)); } return md5.toString(); }catch (NoSuchAlgorithmException e) { throw new MarvelApiException("cannot generate the api key", e); } }    }
@Test public void shouldProvideAValidMd5WhenGiveValidValues() throws Exception { AuthHashGenerator authHashGenerator = new AuthHashGenerator(); String md5 = authHashGenerator.generateHash(ANY_TIMESTAMP, ANY_PUBLIC_KEY, ANY_PRIVATE_KEY); assertEquals(VALID_MD5, md5); }