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 int
private static final org.slf4j.Logger
private 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 ofAllowableValue
elements for eachCharset
.static AllowableValue[]
Returns an array ofAllowableValue
elements for eachHashAlgorithm
.static String
hashValue
(HashAlgorithm algorithm, String value) Returns the hex-encoded hash of the specified value.static String
hashValue
(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 String
hashValueStreaming
(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 ofAllowableValue
elements for eachHashAlgorithm
. The completedescription
is built from the digest length, safety warnings, etc. SeeHashAlgorithm.buildAllowableValueDescription()
.- Returns:
- an ordered
AllowableValue[]
containing the values
-
buildCharacterSetAllowableValues
Returns an array ofAllowableValue
elements for eachCharset
. Only the charsets inStandardCharsets
are returned to be consistent across JVM instances.- Returns:
- an ordered
AllowableValue[]
containing the values
-
getSupportedCharsets
Returns aList
of supportedCharset
s on this platform. This is not a complete list, as only the charsets inStandardCharsets
are 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 anInputStream
to perform the operation in a streaming manner for large inputs.- Parameters:
algorithm
- the hash algorithm to usevalue
- the value to hash (cannot benull
but 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 benull
but 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 benull
but 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 benull
but 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 benull
but 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
-
blake2Hash
-
blake2HashStreaming
private static byte[] blake2HashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException - Throws:
IOException
-