@Test public void hashDataTest() { String data = randomString(1000); byte[] hash = HashUtil.hash(data.getBytes()); assertNotNull(hash); assertEquals(new String(hash), new String(HashUtil.hash(data.getBytes()))); String data2 = randomString(1000); assertNotEquals(data, data2); assertNotEquals(new String(hash), new String(HashUtil.hash(data2.getBytes()))); }
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);  }