public class Argon2SecureHasher extends AbstractSecureHasher
Argon2 for secure password hashing. This class is
roughly based on Spring Security's implementation but does not include the full module
in this utility module. This implementation uses Argon2id which provides a
balance of protection against side-channel and memory attacks.
One critical difference is that this implementation uses a
static universal salt unless instructed otherwise, which provides
strict determinism across nodes in a cluster. The purpose for this is to allow for
blind equality comparison of sensitive values hashed on different nodes (with
potentially different nifi.sensitive.props.key values) during flow inheritance
(see FingerprintFactory).
| Modifier and Type | Field and Description |
|---|---|
private static int |
DEFAULT_HASH_LENGTH |
static int |
DEFAULT_ITERATIONS |
static int |
DEFAULT_MEMORY |
static int |
DEFAULT_PARALLELISM |
private static int |
DEFAULT_SALT_LENGTH |
private Integer |
hashLength |
private Integer |
iterations |
private static org.slf4j.Logger |
logger |
private static int |
MAX_PARALLELISM |
private Integer |
memory |
private static int |
MIN_HASH_LENGTH |
private static int |
MIN_ITERATIONS |
private static int |
MIN_MEMORY_SIZE_KB |
private static int |
MIN_PARALLELISM |
private static int |
MIN_SALT_LENGTH |
private int |
parallelism |
saltLength, UPPER_BOUNDARY| Constructor and Description |
|---|
Argon2SecureHasher()
Instantiates an Argon2 secure hasher using the default cost parameters
(
hashLength = DEFAULT_HASH_LENGTH,
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). |
Argon2SecureHasher(Integer hashLength)
Instantiates an Argon2 secure hasher using the provided hash length and default cost parameters
(
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). |
Argon2SecureHasher(Integer hashLength,
Integer memory,
int parallelism,
Integer iterations)
Instantiates an Argon2 secure hasher using the provided cost parameters.
|
Argon2SecureHasher(Integer hashLength,
Integer memory,
int parallelism,
Integer iterations,
Integer saltLength)
Instantiates an Argon2 secure hasher using the provided cost parameters.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) boolean |
acceptsEmptyInput()
Returns
true if the algorithm can accept empty (non-null) inputs. |
(package private) String |
getAlgorithmName()
Returns the algorithm-specific name for logging and messages.
|
(package private) int |
getDefaultSaltLength()
Returns the algorithm-specific default salt length in bytes.
|
(package private) int |
getMaxSaltLength()
Returns the algorithm-specific maximum salt length in bytes.
|
(package private) int |
getMinSaltLength()
Returns the algorithm-specific minimum salt length in bytes.
|
(package private) byte[] |
hash(byte[] input)
Internal method to hash the raw bytes.
|
(package private) byte[] |
hash(byte[] input,
byte[] rawSalt)
Internal method to hash the raw bytes.
|
static boolean |
isHashLengthValid(Integer hashLength)
Returns whether the provided hash length is within boundaries.
|
static boolean |
isIterationsValid(Integer iterations)
Returns whether the provided iteration count is within boundaries.
|
static boolean |
isMemorySizeValid(Integer memory)
Returns whether the provided memory size is within boundaries.
|
static boolean |
isParallelismValid(int parallelism)
Returns whether the provided parallelization factor is within boundaries.
|
private void |
validateParameters(Integer hashLength,
Integer memory,
int parallelism,
Integer iterations,
Integer saltLength)
Enforces valid Argon2 secure hasher cost parameters are provided.
|
getSalt, hashBase64, hashBase64, hashHex, hashHex, hashRaw, hashRaw, initializeSalt, isSaltLengthValid, isUsingStaticSaltprivate static final org.slf4j.Logger logger
private static final int DEFAULT_HASH_LENGTH
public static final int DEFAULT_PARALLELISM
public static final int DEFAULT_MEMORY
public static final int DEFAULT_ITERATIONS
private static final int DEFAULT_SALT_LENGTH
private static final int MIN_MEMORY_SIZE_KB
private static final int MIN_PARALLELISM
private static final int MAX_PARALLELISM
private static final int MIN_HASH_LENGTH
private static final int MIN_ITERATIONS
private static final int MIN_SALT_LENGTH
private final Integer hashLength
private final Integer memory
private final int parallelism
private final Integer iterations
public Argon2SecureHasher()
hashLength = DEFAULT_HASH_LENGTH,
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). A static salt is also used.public Argon2SecureHasher(Integer hashLength)
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). A static salt is also used.hashLength - the desired hash output length in bytespublic Argon2SecureHasher(Integer hashLength, Integer memory, int parallelism, Integer iterations)
DEFAULT_SALT_LENGTH byte salt will be generated on every hash request.
Integer is used instead of int for parameters which have a max value of 2^32 - 1 to allow for unsigned integers exceeding Integer.MAX_VALUE.hashLength - the output length in bytes (4 to 2^32 - 1)memory - the integer number of KiB used (8p to 2^32 - 1)parallelism - degree of parallelism (1 to 2^24 - 1)iterations - number of iterations (1 to 2^32 - 1)public Argon2SecureHasher(Integer hashLength, Integer memory, int parallelism, Integer iterations, Integer saltLength)
Integer is used instead of int for parameters which have a max value of 2^32 - 1 to allow for unsigned integers exceeding Integer.MAX_VALUE.hashLength - the output length in bytes (4 to 2^32 - 1)memory - the integer number of KiB used (8p to 2^32 - 1)parallelism - degree of parallelism (1 to 2^24 - 1)iterations - number of iterations (1 to 2^32 - 1)saltLength - the salt length in bytes 8 to 2^32 - 1)private void validateParameters(Integer hashLength, Integer memory, int parallelism, Integer iterations, Integer saltLength)
hashLength - the output length in bytes (4 to 2^32 - 1)memory - the integer number of KiB used (8p to 2^32 - 1)parallelism - degree of parallelism (1 to 2^24 - 1)iterations - number of iterations (1 to 2^32 - 1)saltLength - the salt length in bytes 8 to 2^32 - 1)String getAlgorithmName()
getAlgorithmName in class AbstractSecureHasherboolean acceptsEmptyInput()
true if the algorithm can accept empty (non-null) inputs.acceptsEmptyInput in class AbstractSecureHasher"" is allowable inputpublic static boolean isHashLengthValid(Integer hashLength)
hashLength - the output length in bytespublic static boolean isMemorySizeValid(Integer memory)
memory - the integer number of KiB usedpublic static boolean isParallelismValid(int parallelism)
parallelism - degree of parallelismpublic static boolean isIterationsValid(Integer iterations)
iterations - number of iterationsint getDefaultSaltLength()
getDefaultSaltLength in class AbstractSecureHasherint getMinSaltLength()
getMinSaltLength in class AbstractSecureHasherint getMaxSaltLength()
getMaxSaltLength in class AbstractSecureHasherbyte[] hash(byte[] input)
hash in class AbstractSecureHasherinput - the raw bytes to hash (can be length 0)byte[] hash(byte[] input,
byte[] rawSalt)
hash in class AbstractSecureHasherinput - the raw bytes to hash (can be length 0)rawSalt - the raw bytes to saltCopyright © 2022 Apache NiFi Project. All rights reserved.