@Test public void hashStreamExampleDataTest() throws IOException { final String expected = "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="; String data = "hello world"; File file = new File(FileUtils.getTempDirectory(), randomString()); FileUtils.writeStringToFile(file, data); byte[] hash = HashUtil.hash(file); String result = new String(Base64.encode(hash)); assertEquals(expected, result); }
public static byte[] hash(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM); digest.update(data, 0, data.length); return digest.digest(); } catch (NoSuchAlgorithmException e) { logger.error("Invalid hash algorithm {}", HASH_ALGORITHM, e); return new byte[0]; } }
HashUtil { public static byte[] hash(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM); digest.update(data, 0, data.length); return digest.digest(); } catch (NoSuchAlgorithmException e) { logger.error("Invalid hash algorithm {}", HASH_ALGORITHM, e); return new byte[0]; } } }
HashUtil { public static byte[] hash(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM); digest.update(data, 0, data.length); return digest.digest(); } catch (NoSuchAlgorithmException e) { logger.error("Invalid hash algorithm {}", HASH_ALGORITHM, e); return new byte[0]; } } private  HashUtil(); }
HashUtil { public static byte[] hash(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM); digest.update(data, 0, data.length); return digest.digest(); } catch (NoSuchAlgorithmException e) { logger.error("Invalid hash algorithm {}", HASH_ALGORITHM, e); return new byte[0]; } } private  HashUtil(); static byte[] hash(byte[] data); static byte[] hash(File file); static boolean compare(File file, byte[] expectedHash); static boolean compare(byte[] actual, byte[] expected); }
HashUtil { public static byte[] hash(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM); digest.update(data, 0, data.length); return digest.digest(); } catch (NoSuchAlgorithmException e) { logger.error("Invalid hash algorithm {}", HASH_ALGORITHM, e); return new byte[0]; } } private  HashUtil(); static byte[] hash(byte[] data); static byte[] hash(File file); static boolean compare(File file, byte[] expectedHash); static boolean compare(byte[] actual, byte[] expected);  }