public class Argon2CipherProvider extends RandomIVPBECipherProvider
| Modifier and Type | Field and Description |
|---|---|
private static Pattern |
ARGON2_SALT_FORMAT |
private static int |
DEFAULT_ITERATIONS |
private static int |
DEFAULT_MEMORY |
private static int |
DEFAULT_PARALLELISM |
private static int |
DEFAULT_SALT_LENGTH |
private Integer |
iterations |
private static org.slf4j.Logger |
logger |
private Integer |
memory |
private int |
parallelism |
IV_DELIMITER, MAX_IV_LIMIT, MAX_SALT_LIMIT, SALT_DELIMITER| Constructor and Description |
|---|
Argon2CipherProvider()
Instantiates an Argon2 cipher provider using the default cost parameters
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). |
Argon2CipherProvider(Integer memory,
int parallelism,
Integer iterations)
Instantiates an Argon2 cipher provider using the provided cost parameters.
|
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
extractRawSaltFromArgon2Salt(String argon2Salt)
Returns the raw salt contained in the provided Argon2 salt string.
|
static String |
formSalt(byte[] rawSalt,
int memory,
int iterations,
int parallelism)
Returns the formatted Argon2 salt string given the provided parameters.
|
byte[] |
generateSalt()
Returns a random salt suitable for this cipher provider.
|
Cipher |
getCipher(EncryptionMethod encryptionMethod,
String password,
byte[] salt,
byte[] iv,
int keyLength,
boolean encryptMode)
Returns an initialized cipher for the specified algorithm.
|
Cipher |
getCipher(EncryptionMethod encryptionMethod,
String password,
byte[] salt,
int keyLength,
boolean encryptMode)
Returns an initialized cipher for the specified algorithm.
|
int |
getDefaultSaltLength()
Returns the default salt length for this implementation.
|
protected Cipher |
getInitializedCipher(EncryptionMethod encryptionMethod,
String password,
byte[] salt,
byte[] iv,
int keyLength,
boolean encryptMode) |
protected int |
getIterations() |
(package private) org.slf4j.Logger |
getLogger() |
protected int |
getMemory() |
protected int |
getParallelism() |
static boolean |
isArgon2FormattedSalt(String salt)
Returns
true if the salt string is a valid Argon2 salt string ($argon2id$v=19$m=4096,t=3,p=1$abcdefghi..{22}). |
private void |
parseSalt(String argon2Salt,
byte[] rawSalt,
List<Integer> params) |
readIV, readSalt, writeIV, writeSaltprivate static final org.slf4j.Logger logger
private static final int DEFAULT_PARALLELISM
private static final int DEFAULT_MEMORY
private static final int DEFAULT_ITERATIONS
private static final int DEFAULT_SALT_LENGTH
private final Integer memory
private final int parallelism
private final Integer iterations
private static final Pattern ARGON2_SALT_FORMAT
public Argon2CipherProvider()
memory = DEFAULT_MEMORY,
parallelism = DEFAULT_PARALLELISM,
iterations = DEFAULT_ITERATIONS). A static salt is also used.public Argon2CipherProvider(Integer memory, int parallelism, Integer iterations)
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 Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, byte[] iv, int keyLength, boolean encryptMode) throws Exception
getCipher in class RandomIVPBECipherProviderencryptionMethod - the EncryptionMethodpassword - the secret inputsalt - the complete salt (e.g. "$argon2id$v=19$m=1024,t=3,p=1$ftvICs8WpASuN3FnRIDcRA$eB912UtYgZjKdwK64V7pfmMiDbsaPK+hts6H6cSHl3I".getBytes(StandardCharsets.UTF_8))iv - the IVkeyLength - the desired key length in bitsencryptMode - true for encrypt, false for decryptException - if there is a problem initializing the cipherorg.slf4j.Logger getLogger()
getLogger in class RandomIVPBECipherProviderpublic Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, int keyLength, boolean encryptMode) throws Exception
The IV can be retrieved by the calling method using Cipher.getIV().
encryptionMethod - the EncryptionMethodpassword - the secret inputsalt - the complete salt (e.g. "$argon2id$v=19$m=1024,t=3,p=1$ftvICs8WpASuN3FnRIDcRA$eB912UtYgZjKdwK64V7pfmMiDbsaPK+hts6H6cSHl3I".getBytes(StandardCharsets.UTF_8))keyLength - the desired key length in bitsencryptMode - true for encrypt, false for decryptException - if there is a problem initializing the cipherprotected Cipher getInitializedCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, byte[] iv, int keyLength, boolean encryptMode) throws Exception
Exceptionpublic static byte[] extractRawSaltFromArgon2Salt(String argon2Salt)
argon2Salt - the full Argon2 saltpublic static boolean isArgon2FormattedSalt(String salt)
true if the salt string is a valid Argon2 salt string ($argon2id$v=19$m=4096,t=3,p=1$abcdefghi..{22}).salt - the salt string to evaluatepublic byte[] generateSalt()
PBECipherProviderPBECipherProvider.getDefaultSaltLength()public static String formSalt(byte[] rawSalt, int memory, int iterations, int parallelism)
$argon2id$v=19$m=4096,t=3,p=1$abcdefABCDEF0123456789
rawSalt - the salt bytesmemory - the memory cost in KiBiterations - the iterationsparallelism - the parallelism factorpublic int getDefaultSaltLength()
PBECipherProviderprotected int getMemory()
protected int getParallelism()
protected int getIterations()
Copyright © 2022 Apache NiFi Project. All rights reserved.