public class PBKDF2SecureHasher extends AbstractSecureHasher
PBKDF2
for secure password hashing.
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
).
The resulting output is referred to as a hash to be consistent with SecureHasher
terminology.
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_DK_LENGTH |
private static int |
DEFAULT_ITERATION_COUNT
This can be calculated automatically using the code
PBKDF2CipherProviderGroovyTest#calculateMinimumIterationCount or manually updated by a maintainer |
private static String |
DEFAULT_PRF |
private static int |
DEFAULT_SALT_LENGTH |
private int |
dkLength |
private Integer |
iterationCount |
private static org.slf4j.Logger |
logger |
private static int |
MIN_DK_LENGTH |
private static int |
MIN_ITERATION_COUNT |
private static int |
MIN_SALT_LENGTH |
private org.bouncycastle.crypto.Digest |
prf |
saltLength, UPPER_BOUNDARY
Constructor and Description |
---|
PBKDF2SecureHasher()
Instantiates a PBKDF2 secure hasher with the default number of iterations and the default PRF.
|
PBKDF2SecureHasher(int dkLength)
Instantiates a PBKDF2 secure hasher with the default number of iterations and the default PRF using the specified derived key length.
|
PBKDF2SecureHasher(int iterationCount,
int dkLength)
Instantiates a PBKDF2 secure hasher with the provided number of iterations and derived key (output) length in bytes, using the default PRF (
SHA512 ). |
PBKDF2SecureHasher(String prf,
Integer iterationCount,
int saltLength,
int dkLength)
Instantiates a PBKDF2 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.
|
private static int |
getMaxDKLength(int hLen)
Returns the maximum length of the derived key in bytes given the digest length in bytes of the underlying PRF.
|
(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 |
isDKLengthValid(int hLen,
Integer dkLength)
Returns whether the provided hash (derived key) length is within boundaries given the configured PRF.
|
static boolean |
isIterationCountValid(Integer iterationCount)
Returns true if the provided cost factor is within boundaries.
|
private org.bouncycastle.crypto.Digest |
resolvePRF(String prf) |
private void |
validateParameters(String prf,
Integer iterationCount,
int saltLength,
int dkLength)
Enforces valid PBKDF2 secure hasher cost parameters are provided.
|
getSalt, hashBase64, hashBase64, hashHex, hashHex, hashRaw, hashRaw, initializeSalt, isSaltLengthValid, isUsingStaticSalt
private static final org.slf4j.Logger logger
private static final String DEFAULT_PRF
private static final int DEFAULT_SALT_LENGTH
private static final int DEFAULT_ITERATION_COUNT
PBKDF2CipherProviderGroovyTest#calculateMinimumIterationCount
or manually updated by a maintainerprivate static final int DEFAULT_DK_LENGTH
private static final int MIN_ITERATION_COUNT
private static final int MIN_DK_LENGTH
private static final int MIN_SALT_LENGTH
private final org.bouncycastle.crypto.Digest prf
private final Integer iterationCount
private final int dkLength
public PBKDF2SecureHasher()
public PBKDF2SecureHasher(int dkLength)
dkLength
- Derived Key Length in bytespublic PBKDF2SecureHasher(int iterationCount, int dkLength)
SHA512
).iterationCount
- the number of iterationsdkLength
- the desired output length in bytespublic PBKDF2SecureHasher(String prf, Integer iterationCount, int saltLength, int dkLength)
MD5
(deprecated), SHA1
(deprecated), SHA256
,
SHA384
, and SHA512
. Unknown PRFs will default to SHA512
.prf
- a String representation of the PRF name, e.g. "SHA256", "SHA-384" "sha_512"iterationCount
- the number of iterationssaltLength
- the salt length in bytes (>= 8
, 0
indicates a static salt)dkLength
- the output length in bytes (1 to (2^32 - 1) * hLen
)private void validateParameters(String prf, Integer iterationCount, int saltLength, int dkLength)
iterationCount
- the (log) number of key expansion roundssaltLength
- the salt length in bytes >= 8
)dkLength
- the output length in bytes (1 to (2^32 - 1) * hLen
)String getAlgorithmName()
getAlgorithmName
in class AbstractSecureHasher
boolean acceptsEmptyInput()
true
if the algorithm can accept empty (non-null
) inputs.acceptsEmptyInput
in class AbstractSecureHasher
""
is allowable inputpublic static boolean isIterationCountValid(Integer iterationCount)
iterationCount
- the (log) number of key expansion roundsint getDefaultSaltLength()
getDefaultSaltLength
in class AbstractSecureHasher
int getMinSaltLength()
getMinSaltLength
in class AbstractSecureHasher
int getMaxSaltLength()
getMaxSaltLength
in class AbstractSecureHasher
public static boolean isDKLengthValid(int hLen, Integer dkLength)
hLen
- the PRF digest size in bytesdkLength
- the output length in bytesprivate static int getMaxDKLength(int hLen)
Integer.MAX_VALUE
, that is returned instead, as RFC 8018 specifies
keyLength INTEGER (1..MAX) OPTIONAL
.hLen
- the length of the PRF digest output in bytesbyte[] hash(byte[] input)
hash
in class AbstractSecureHasher
input
- the raw bytes to hash (can be length 0)byte[] hash(byte[] input, byte[] rawSalt)
hash
in class AbstractSecureHasher
input
- the raw bytes to hash (can be length 0)rawSalt
- the raw bytes to saltprivate org.bouncycastle.crypto.Digest resolvePRF(String prf)
Copyright © 2022 Apache NiFi Project. All rights reserved.