public class BcryptCipherProvider extends RandomIVPBECipherProvider
Modifier and Type | Field and Description |
---|---|
private static Pattern |
BCRYPT_SALT_FORMAT |
private static int |
DEFAULT_SALT_LENGTH |
private static int |
DEFAULT_WORK_FACTOR
This can be calculated automatically using the code
BcryptCipherProviderGroovyTest#calculateMinimumWorkFactor or manually updated by a maintainer |
private static org.slf4j.Logger |
logger |
private int |
workFactor |
IV_DELIMITER, MAX_IV_LIMIT, MAX_SALT_LIMIT, SALT_DELIMITER
Constructor and Description |
---|
BcryptCipherProvider()
Instantiates a Bcrypt cipher provider with the default work factor 12 (2^12 key expansion rounds).
|
BcryptCipherProvider(int workFactor)
Instantiates a Bcrypt cipher provider with the specified work factor w (2^w key expansion rounds).
|
Modifier and Type | Method and Description |
---|---|
private String |
formatSaltForBcrypt(byte[] salt) |
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 |
getWorkFactor() |
readIV, readSalt, writeIV, writeSalt
private static final org.slf4j.Logger logger
private final int workFactor
private static final int DEFAULT_WORK_FACTOR
BcryptCipherProviderGroovyTest#calculateMinimumWorkFactor
or manually updated by a maintainerprivate static final int DEFAULT_SALT_LENGTH
private static final Pattern BCRYPT_SALT_FORMAT
public BcryptCipherProvider()
public BcryptCipherProvider(int workFactor)
workFactor
- the (log) number of key expansion rounds [4..30]public Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, byte[] iv, int keyLength, boolean encryptMode) throws Exception
getCipher
in class RandomIVPBECipherProvider
encryptionMethod
- the EncryptionMethod
password
- 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 RandomIVPBECipherProvider
public Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, int keyLength, boolean encryptMode) throws Exception
Cipher.getIV()
.encryptionMethod
- the EncryptionMethod
password
- the secret inputsalt
- the complete salt (e.g. "$2a$10$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
Exception
private String formatSaltForBcrypt(byte[] salt)
public byte[] generateSalt()
PBECipherProvider
PBECipherProvider.getDefaultSaltLength()
public int getDefaultSaltLength()
PBECipherProvider
protected int getWorkFactor()
Copyright © 2018 Apache NiFi Project. All rights reserved.