Class HashService
java.lang.Object
org.apache.nifi.security.util.crypto.HashService
This class provides a generic service for cryptographic hashing.
See also:
* HashAlgorithm
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final org.slf4j.Loggerprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]blake2Hash(HashAlgorithm algorithm, byte[] value) private static byte[]blake2HashStreaming(HashAlgorithm algorithm, InputStream value) static AllowableValue[]Returns an array ofAllowableValueelements for eachCharset.static AllowableValue[]Returns an array ofAllowableValueelements for eachHashAlgorithm.private static MessageDigestgetMessageDigest(HashAlgorithm algorithm) static StringhashValue(HashAlgorithm algorithm, String value) Returns the hex-encoded hash of the specified value.static StringhashValue(HashAlgorithm algorithm, String value, Charset charset) Returns the hex-encoded hash of the specified value.static byte[]hashValueRaw(HashAlgorithm algorithm, byte[] value) Returns the rawbyte[]hash of the specified value.static byte[]hashValueRaw(HashAlgorithm algorithm, String value) Returns the rawbyte[]hash of the specified value.static byte[]hashValueRaw(HashAlgorithm algorithm, String value, Charset charset) Returns the rawbyte[]hash of the specified value.static StringhashValueStreaming(HashAlgorithm algorithm, InputStream value) Returns the hash of the specified value.private static byte[]traditionalHash(HashAlgorithm algorithm, byte[] value) private static byte[]traditionalHashStreaming(HashAlgorithm algorithm, InputStream value)
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
UTF_16_DESCRIPTION
- See Also:
-
-
Constructor Details
-
HashService
public HashService()
-
-
Method Details
-
buildHashAlgorithmAllowableValues
Returns an array ofAllowableValueelements for eachHashAlgorithm. The completedescriptionis built from the digest length, safety warnings, etc. SeeHashAlgorithm.buildAllowableValueDescription().- Returns:
- an ordered
AllowableValue[]containing the values
-
buildCharacterSetAllowableValues
Returns an array ofAllowableValueelements for eachCharset. Only the charsets inStandardCharsetsare returned to be consistent across JVM instances.- Returns:
- an ordered
AllowableValue[]containing the values
-
getSupportedCharsets
Returns aListof supportedCharsets on this platform. This is not a complete list, as only the charsets inStandardCharsetsare returned to be consistent across JVM instances.- Returns:
- the list of charsets
-
hashValueStreaming
public static String hashValueStreaming(HashAlgorithm algorithm, InputStream value) throws IOException Returns the hash of the specified value. This method uses anInputStreamto perform the operation in a streaming manner for large inputs.- Parameters:
algorithm- the hash algorithm to usevalue- the value to hash (cannot benullbut can be an empty stream)- Returns:
- the hash value in hex
- Throws:
IOException
-
hashValue
Returns the hex-encoded hash of the specified value.- Parameters:
algorithm- the hash algorithm to usevalue- the value to hash (cannot benullbut can be an empty String)charset- the charset to use- Returns:
- the hash value in hex
-
hashValue
Returns the hex-encoded hash of the specified value. The default charset (StandardCharsets.UTF_8) is used.- Parameters:
algorithm- the hash algorithm to usevalue- the value to hash (cannot benullbut can be an empty String)- Returns:
- the hash value in hex
-
hashValueRaw
Returns the rawbyte[]hash of the specified value.- Parameters:
algorithm- the hash algorithm to usevalue- the value to hash (cannot benullbut can be an empty String)charset- the charset to use- Returns:
- the hash value in bytes
-
hashValueRaw
Returns the rawbyte[]hash of the specified value. The default charset (StandardCharsets.UTF_8) is used.- Parameters:
algorithm- the hash algorithm to usevalue- the value to hash (cannot benullbut can be an empty String)- Returns:
- the hash value in bytes
-
hashValueRaw
Returns the rawbyte[]hash of the specified value.- Parameters:
algorithm- the hash algorithm to usevalue- the value to hash- Returns:
- the hash value in bytes
-
traditionalHash
-
traditionalHashStreaming
private static byte[] traditionalHashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException - Throws:
IOException
-
getMessageDigest
-
blake2Hash
-
blake2HashStreaming
private static byte[] blake2HashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException - Throws:
IOException
-