public class Argon2SecureHasher extends Object implements SecureHasher
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 |
private static int |
DEFAULT_ITERATIONS |
private static int |
DEFAULT_MEMORY |
private static int |
DEFAULT_PARALLELISM |
private int |
hashLength |
private int |
iterations |
private static org.slf4j.Logger |
logger |
private int |
memory |
private int |
parallelism |
private int |
saltLength |
private static byte[] |
staticSalt |
private boolean |
usingStaticSalt |
| 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(int hashLength,
int memory,
int parallelism,
int iterations)
Instantiates an Argon2 secure hasher using the provided cost parameters.
|
Argon2SecureHasher(int hashLength,
int memory,
int parallelism,
int iterations,
int saltLength)
Instantiates an Argon2 secure hasher using the provided cost parameters.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) byte[] |
getSalt()
Returns a salt to use.
|
private byte[] |
hash(byte[] input)
Internal method to hash the raw bytes.
|
String |
hashBase64(String input)
Returns a String representation of
Argon2(input) in Base 64-encoded format. |
String |
hashHex(String input)
Returns a String representation of
Argon2(input) in hex-encoded format. |
byte[] |
hashRaw(byte[] input)
Returns a byte[] representation of
Argon2(input). |
boolean |
isUsingStaticSalt()
Returns
true if this instance is configured to use a static salt. |
private static final org.slf4j.Logger logger
private static final int DEFAULT_HASH_LENGTH
private static final int DEFAULT_PARALLELISM
private static final int DEFAULT_MEMORY
private static final int DEFAULT_ITERATIONS
private final int hashLength
private final int memory
private final int parallelism
private final int iterations
private final int saltLength
private final boolean usingStaticSalt
private static final byte[] staticSalt
public Argon2SecureHasher()
hashLength = DEFAULT_HASH_LENGTH,
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). A static salt is also used.public Argon2SecureHasher(int hashLength,
int memory,
int parallelism,
int iterations)
#DEFAULT_SALT_LENGTH byte salt will be generated on every hash request.hashLength - the output length in bytes (4 to 2^32 - 1)memory - the integer number of KB 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(int hashLength,
int memory,
int parallelism,
int iterations,
int saltLength)
hashLength - the output length in bytes (4 to 2^32 - 1)memory - the integer number of KB 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)public boolean isUsingStaticSalt()
true if this instance is configured to use a static salt.byte[] getSalt()
isUsingStaticSalt()),
this return value will be identical across every invocation. If using a dynamic salt,
it will be saltLength bytes of a securely-generated random value.public String hashHex(String input)
Argon2(input) in hex-encoded format.hashHex in interface SecureHasherinput - the inputpublic String hashBase64(String input)
Argon2(input) in Base 64-encoded format.hashBase64 in interface SecureHasherinput - the inputpublic byte[] hashRaw(byte[] input)
Argon2(input).hashRaw in interface SecureHasherinput - the inputprivate byte[] hash(byte[] input)
input - the raw bytes to hash (can be length 0)Copyright © 2020 Apache NiFi Project. All rights reserved.