Class HashService

java.lang.Object
org.apache.nifi.security.util.crypto.HashService

public class HashService extends Object
This class provides a generic service for cryptographic hashing.

See also: * HashAlgorithm

  • Field Details

  • Constructor Details

    • HashService

      public HashService()
  • Method Details

    • buildHashAlgorithmAllowableValues

      public static AllowableValue[] buildHashAlgorithmAllowableValues()
      Returns an array of AllowableValue elements for each HashAlgorithm. The complete description is built from the digest length, safety warnings, etc. See HashAlgorithm.buildAllowableValueDescription().
      Returns:
      an ordered AllowableValue[] containing the values
    • buildCharacterSetAllowableValues

      public static AllowableValue[] buildCharacterSetAllowableValues()
      Returns an array of AllowableValue elements for each Charset. Only the charsets in StandardCharsets are returned to be consistent across JVM instances.
      Returns:
      an ordered AllowableValue[] containing the values
    • getSupportedCharsets

      public static List<Charset> getSupportedCharsets()
      Returns a List of supported Charsets on this platform. This is not a complete list, as only the charsets in StandardCharsets 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 an InputStream to perform the operation in a streaming manner for large inputs.
      Parameters:
      algorithm - the hash algorithm to use
      value - the value to hash (cannot be null but can be an empty stream)
      Returns:
      the hash value in hex
      Throws:
      IOException
    • hashValue

      public static String hashValue(HashAlgorithm algorithm, String value, Charset charset)
      Returns the hex-encoded hash of the specified value.
      Parameters:
      algorithm - the hash algorithm to use
      value - the value to hash (cannot be null but can be an empty String)
      charset - the charset to use
      Returns:
      the hash value in hex
    • hashValue

      public static String hashValue(HashAlgorithm algorithm, String value)
      Returns the hex-encoded hash of the specified value. The default charset (StandardCharsets.UTF_8) is used.
      Parameters:
      algorithm - the hash algorithm to use
      value - the value to hash (cannot be null but can be an empty String)
      Returns:
      the hash value in hex
    • hashValueRaw

      public static byte[] hashValueRaw(HashAlgorithm algorithm, String value, Charset charset)
      Returns the raw byte[] hash of the specified value.
      Parameters:
      algorithm - the hash algorithm to use
      value - the value to hash (cannot be null but can be an empty String)
      charset - the charset to use
      Returns:
      the hash value in bytes
    • hashValueRaw

      public static byte[] hashValueRaw(HashAlgorithm algorithm, String value)
      Returns the raw byte[] hash of the specified value. The default charset (StandardCharsets.UTF_8) is used.
      Parameters:
      algorithm - the hash algorithm to use
      value - the value to hash (cannot be null but can be an empty String)
      Returns:
      the hash value in bytes
    • hashValueRaw

      public static byte[] hashValueRaw(HashAlgorithm algorithm, byte[] value)
      Returns the raw byte[] hash of the specified value.
      Parameters:
      algorithm - the hash algorithm to use
      value - the value to hash
      Returns:
      the hash value in bytes
    • traditionalHash

      private static byte[] traditionalHash(HashAlgorithm algorithm, byte[] value)
    • traditionalHashStreaming

      private static byte[] traditionalHashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException
      Throws:
      IOException
    • blake2Hash

      private static byte[] blake2Hash(HashAlgorithm algorithm, byte[] value)
    • blake2HashStreaming

      private static byte[] blake2HashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException
      Throws:
      IOException