private static byte[] blake2HashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException { int digestLengthBytes = algorithm.getDigestBytesLength(); Blake2bDigest blake2bDigest = new Blake2bDigest(digestLengthBytes * 8); byte[] rawHash = new byte[blake2bDigest.getDigestSize()]; final byte[] buffer = new byte[BUFFER_SIZE]; int read = value.read(buffer, 0, BUFFER_SIZE); while (read > -1) { blake2bDigest.update(buffer, 0, read); read = value.read(buffer, 0, BUFFER_SIZE); } blake2bDigest.doFinal(rawHash, 0); return rawHash; } }
private static byte[] blake2Hash(HashAlgorithm algorithm, byte[] value) { int digestLengthBytes = algorithm.getDigestBytesLength(); Blake2bDigest blake2bDigest = new Blake2bDigest(digestLengthBytes * 8); byte[] rawHash = new byte[blake2bDigest.getDigestSize()]; blake2bDigest.update(value, 0, value.length); blake2bDigest.doFinal(rawHash, 0); return rawHash; }
private static byte[] blake2HashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException { int digestLengthBytes = algorithm.getDigestBytesLength(); Blake2bDigest blake2bDigest = new Blake2bDigest(digestLengthBytes * 8); byte[] rawHash = new byte[blake2bDigest.getDigestSize()]; final byte[] buffer = new byte[BUFFER_SIZE]; int read = value.read(buffer, 0, BUFFER_SIZE); while (read > -1) { blake2bDigest.update(buffer, 0, read); read = value.read(buffer, 0, BUFFER_SIZE); } blake2bDigest.doFinal(rawHash, 0); return rawHash; } }
private static byte[] blake2Hash(HashAlgorithm algorithm, byte[] value) { int digestLengthBytes = algorithm.getDigestBytesLength(); Blake2bDigest blake2bDigest = new Blake2bDigest(digestLengthBytes * 8); byte[] rawHash = new byte[blake2bDigest.getDigestSize()]; blake2bDigest.update(value, 0, value.length); blake2bDigest.doFinal(rawHash, 0); return rawHash; }