/** * Returns the hash of the specified value. This method uses an {@link java.io.InputStream} to perform the operation in a streaming manner for large inputs. * * @param algorithm the hash algorithm to use * @param value the value to hash (cannot be {@code null} but can be an empty stream) * @return the hash value in hex */ public static String hashValueStreaming(HashAlgorithm algorithm, InputStream value) throws IOException { if (algorithm == null) { throw new IllegalArgumentException("The hash algorithm cannot be null"); } if (value == null) { throw new IllegalArgumentException("The value cannot be null"); } // The Blake2 algorithms are instantiated differently and rely on BouncyCastle if (algorithm.isBlake2()) { return Hex.encodeHexString(blake2HashStreaming(algorithm, value)); } else { return Hex.encodeHexString(traditionalHashStreaming(algorithm, value)); } }
/** * Returns the hash of the specified value. This method uses an {@link java.io.InputStream} to perform the operation in a streaming manner for large inputs. * * @param algorithm the hash algorithm to use * @param value the value to hash (cannot be {@code null} but can be an empty stream) * @return the hash value in hex */ public static String hashValueStreaming(HashAlgorithm algorithm, InputStream value) throws IOException { if (algorithm == null) { throw new IllegalArgumentException("The hash algorithm cannot be null"); } if (value == null) { throw new IllegalArgumentException("The value cannot be null"); } // The Blake2 algorithms are instantiated differently and rely on BouncyCastle if (algorithm.isBlake2()) { return Hex.encodeHexString(blake2HashStreaming(algorithm, value)); } else { return Hex.encodeHexString(traditionalHashStreaming(algorithm, value)); } }