public class ScryptCipherProvider extends RandomIVPBECipherProvider
| Modifier and Type | Field and Description |
|---|---|
private static int |
DEFAULT_N
These values can be calculated automatically using the code
ScryptCipherProviderGroovyTest#calculateMinimumParameters or manually updated by a maintainer |
private static int |
DEFAULT_P |
private static int |
DEFAULT_R |
private static org.slf4j.Logger |
logger |
private static Pattern |
MCRYPT_SALT_FORMAT |
private int |
n |
private int |
p |
private int |
r |
private static Pattern |
SCRYPT_SALT_FORMAT |
IV_DELIMITER, MAX_IV_LIMIT, MAX_SALT_LIMIT, SALT_DELIMITER| Constructor and Description |
|---|
ScryptCipherProvider()
Instantiates a Scrypt cipher provider with the default parameters N=2^14, r=8, p=1.
|
ScryptCipherProvider(int n,
int r,
int p)
Instantiates a Scrypt cipher provider with the specified N, r, p values.
|
| Modifier and Type | Method and Description |
|---|---|
private String |
formatSaltForScrypt(byte[] salt)
Formats the salt into a string which Scrypt can understand containing the N, r, p values along with the salt value.
|
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) |
(package private) org.slf4j.Logger |
getLogger() |
protected int |
getN() |
protected int |
getP() |
protected int |
getR() |
static boolean |
isPValid(int r,
int p)
Returns whether the provided parallelization factor (p value) is within boundaries.
|
static boolean |
isRValid(int r)
Returns whether the provided block size (r value) is a positive integer or not.
|
private void |
parseSalt(String scryptSalt,
byte[] rawSalt,
List<Integer> params) |
String |
translateSalt(String mcryptSalt)
Translates a salt from the mcrypt format
$n$r$p$salt_hex to the Java scrypt format $s0$params$saltBase64. |
readIV, readSalt, writeIV, writeSaltprivate static final org.slf4j.Logger logger
private final int n
private final int r
private final int p
private static final int DEFAULT_N
ScryptCipherProviderGroovyTest#calculateMinimumParameters or manually updated by a maintainerprivate static final int DEFAULT_R
private static final int DEFAULT_P
private static final Pattern SCRYPT_SALT_FORMAT
private static final Pattern MCRYPT_SALT_FORMAT
public ScryptCipherProvider()
public ScryptCipherProvider(int n,
int r,
int p)
n - the number of iterationsr - the block size in bytesp - the parallelization factorpublic static boolean isPValid(int r,
int p)
r - the block size in bytesp - the parallelization factorpublic static boolean isRValid(int r)
r - the block size in bytespublic 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. "$2a$10$gUVbkVzp79H8YaCOsCVZNu".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. "$s0$20101$gUVbkVzp79H8YaCOsCVZNu".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
Exceptionprivate String formatSaltForScrypt(byte[] salt)
salt - the provided saltpublic String translateSalt(String mcryptSalt)
$n$r$p$salt_hex to the Java scrypt format $s0$params$saltBase64.mcryptSalt - the mcrypt-formatted salt stringpublic byte[] generateSalt()
PBECipherProviderPBECipherProvider.getDefaultSaltLength()public int getDefaultSaltLength()
PBECipherProviderprotected int getN()
protected int getR()
protected int getP()
Copyright © 2019 Apache NiFi Project. All rights reserved.