public abstract class AbstractSecureHasher extends Object implements SecureHasher
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
logger |
protected int |
saltLength |
private static byte[] |
STATIC_SALT |
(package private) static Integer |
UPPER_BOUNDARY |
private boolean |
usingStaticSalt |
Constructor and Description |
---|
AbstractSecureHasher() |
Modifier and Type | Method and Description |
---|---|
(package private) abstract boolean |
acceptsEmptyInput()
Returns
true if the algorithm can accept empty (non-null ) inputs. |
(package private) abstract String |
getAlgorithmName()
Returns the algorithm-specific name for logging and messages.
|
(package private) abstract int |
getDefaultSaltLength()
Returns the algorithm-specific default salt length in bytes.
|
(package private) abstract int |
getMaxSaltLength()
Returns the algorithm-specific maximum salt length in bytes.
|
(package private) abstract int |
getMinSaltLength()
Returns the algorithm-specific minimum salt length in bytes.
|
(package private) byte[] |
getSalt()
Returns a salt to use.
|
(package private) abstract byte[] |
hash(byte[] input)
Returns the algorithm-specific calculated hash for the input and generates or retrieves the salt according to
the configured salt length.
|
(package private) abstract byte[] |
hash(byte[] input,
byte[] salt)
Returns the algorithm-specific calculated hash for the input and salt.
|
String |
hashBase64(String input)
Returns a String representation of the hash in Base 64-encoded format.
|
String |
hashBase64(String input,
String salt)
Returns a String representation of the hash in Base 64-encoded format.
|
String |
hashHex(String input)
Returns a String representation of the hash in hex-encoded format.
|
String |
hashHex(String input,
String salt)
Returns a String representation of the hash in hex-encoded format.
|
byte[] |
hashRaw(byte[] input)
Returns a byte[] representation of
SecureHasher.hash(input) . |
byte[] |
hashRaw(byte[] input,
byte[] salt)
Returns a byte[] representation of
SecureHasher.hash(input) . |
protected void |
initializeSalt(Integer saltLength)
Verifies the salt length is valid for this algorithm and if a static salt should be used.
|
boolean |
isSaltLengthValid(Integer saltLength)
Returns whether the provided salt length (saltLength) is within boundaries.
|
boolean |
isUsingStaticSalt()
Returns
true if this instance is configured to use a static salt. |
private String |
validateInput(String input)
Returns the valid
input String (if the algorithm accepts empty input, changes null to "" ; if not, throws IllegalArgumentException ). |
private static final org.slf4j.Logger logger
protected int saltLength
private boolean usingStaticSalt
private static final byte[] STATIC_SALT
static final Integer UPPER_BOUNDARY
protected void initializeSalt(Integer saltLength)
saltLength
- the salt length in bytespublic boolean isSaltLengthValid(Integer saltLength)
Integer.MAX_VALUE
. This method is not static
because it depends on the
instantiation of the algorithm-specific concrete class.saltLength
- the salt length in bytesabstract int getDefaultSaltLength()
abstract int getMinSaltLength()
abstract int getMaxSaltLength()
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.abstract String getAlgorithmName()
abstract boolean acceptsEmptyInput()
true
if the algorithm can accept empty (non-null
) inputs.""
is allowable inputpublic String hashHex(String input)
hashHex
in interface SecureHasher
input
- the non-empty inputpublic String hashHex(String input, String salt)
hashHex
in interface SecureHasher
input
- the non-empty inputsalt
- the provided saltpublic String hashBase64(String input)
hashBase64
in interface SecureHasher
input
- the non-empty inputpublic String hashBase64(String input, String salt)
hashBase64
in interface SecureHasher
input
- the non-empty inputsalt
- the provided saltpublic byte[] hashRaw(byte[] input)
SecureHasher.hash(input)
.hashRaw
in interface SecureHasher
input
- the inputpublic byte[] hashRaw(byte[] input, byte[] salt)
SecureHasher.hash(input)
.hashRaw
in interface SecureHasher
input
- the inputsalt
- the provided saltprivate String validateInput(String input)
input
String (if the algorithm accepts empty input, changes null
to ""
; if not, throws IllegalArgumentException
).input
- the input to validateabstract byte[] hash(byte[] input)
input
- the input in raw bytesabstract byte[] hash(byte[] input, byte[] salt)
input
- the input in raw bytessalt
- the provided saltCopyright © 2021 Apache NiFi Project. All rights reserved.