private static byte[] traditionalHash(HashAlgorithm algorithm, byte[] value) { return DigestUtils.getDigest(algorithm.getName()).digest(value); }
/** * Returns an array of {@link AllowableValue} elements for each {@link HashAlgorithm}. The * complete {@code description} is built from the digest length, safety warnings, etc. See * {@link HashAlgorithm#buildAllowableValueDescription()}. * * @return an ordered {@code AllowableValue[]} containing the values */ public static AllowableValue[] buildHashAlgorithmAllowableValues() { final HashAlgorithm[] hashAlgorithms = HashAlgorithm.values(); List<AllowableValue> allowableValues = new ArrayList<>(hashAlgorithms.length); for (HashAlgorithm algorithm : hashAlgorithms) { allowableValues.add(new AllowableValue(algorithm.getName(), algorithm.getName(), algorithm.buildAllowableValueDescription())); } return allowableValues.toArray(new AllowableValue[0]); }
private static byte[] traditionalHashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException { MessageDigest digest = DigestUtils.getDigest(algorithm.getName()); // DigestInputStream digestInputStream = new DigestInputStream(value, digest); return DigestUtils.digest(digest, value); }
private String hashValue(HashAlgorithm algorithm, String value, Charset charset) { if (value == null) { getLogger().warn("Tried to calculate {} hash of null value; returning empty string", new Object[]{algorithm.getName()}); return ""; } return HashService.hashValue(algorithm, value, charset); }
private static byte[] traditionalHash(HashAlgorithm algorithm, byte[] value) { return DigestUtils.getDigest(algorithm.getName()).digest(value); }
/** * Returns an array of {@link AllowableValue} elements for each {@link HashAlgorithm}. The * complete {@code description} is built from the digest length, safety warnings, etc. See * {@link HashAlgorithm#buildAllowableValueDescription()}. * * @return an ordered {@code AllowableValue[]} containing the values */ public static AllowableValue[] buildHashAlgorithmAllowableValues() { final HashAlgorithm[] hashAlgorithms = HashAlgorithm.values(); List<AllowableValue> allowableValues = new ArrayList<>(hashAlgorithms.length); for (HashAlgorithm algorithm : hashAlgorithms) { allowableValues.add(new AllowableValue(algorithm.getName(), algorithm.getName(), algorithm.buildAllowableValueDescription())); } return allowableValues.toArray(new AllowableValue[0]); }
private static byte[] traditionalHashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException { MessageDigest digest = DigestUtils.getDigest(algorithm.getName()); // DigestInputStream digestInputStream = new DigestInputStream(value, digest); return DigestUtils.digest(digest, value); }
private String hashValue(HashAlgorithm algorithm, String value, Charset charset) { if (value == null) { getLogger().warn("Tried to calculate {} hash of null value; returning empty string", new Object[]{algorithm.getName()}); return ""; } return HashService.hashValue(algorithm, value, charset); }