ChecksumUtil { public static byte[] hexStringToByteArray(String s) { byte[] b = new byte[s.length() / 2]; for (int i = 0; i < b.length; i++) { int index = i * 2; int v = Integer.parseInt(s.substring(index, index + 2), 16); b[i] = (byte) v; } return b; } ChecksumUtil(Algorithm alg); String generateChecksum(File file); String generateChecksum(InputStream inStream); String generateChecksum(String string); String generateChecksumBase64(String string); static DigestInputStream wrapStream(InputStream inStream,
                                               Algorithm algorithm); static String getChecksum(DigestInputStream digestStream); static byte[] getChecksumBytes(DigestInputStream digestStream); static String checksumBytesToString(byte[] digestBytes); static byte[] hexStringToByteArray(String s); static String convertToBase64Encoding(String hexEncodedChecksum);  }
@Test public void testHexStringToByteArray() throws Exception { ChecksumUtil util = new ChecksumUtil(Algorithm.MD5); String md5 = util.generateChecksum(getStream(content)); byte[] checksumBytes = ChecksumUtil.hexStringToByteArray(md5); String checksum = ChecksumUtil.checksumBytesToString(checksumBytes); assertEquals(md5, checksum); }