public class OpenSSLPKCS5CipherProvider extends Object implements PBECipherProvider
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_SALT_LENGTH |
private static byte[] |
EMPTY_SALT |
private static int |
ITERATION_COUNT |
private static org.slf4j.Logger |
logger |
private static String |
OPENSSL_EVP_HEADER_MARKER |
private static int |
OPENSSL_EVP_HEADER_SIZE |
Constructor and Description |
---|
OpenSSLPKCS5CipherProvider() |
Modifier and Type | Method and Description |
---|---|
byte[] |
generateSalt()
Returns a random salt suitable for this cipher provider.
|
Cipher |
getCipher(EncryptionMethod encryptionMethod,
String password,
boolean encryptMode)
Convenience method without key length parameter.
|
Cipher |
getCipher(EncryptionMethod encryptionMethod,
String password,
byte[] salt,
boolean encryptMode)
Convenience method without key length parameter.
|
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,
boolean encryptMode) |
protected int |
getIterationCount() |
byte[] |
readSalt(InputStream in)
Returns the salt provided as part of the cipher stream, or throws an exception if one cannot be detected.
|
protected void |
validateSalt(EncryptionMethod encryptionMethod,
byte[] salt) |
void |
writeSalt(byte[] salt,
OutputStream out)
Writes the salt provided as part of the cipher stream, or throws an exception if it cannot be written.
|
private static final org.slf4j.Logger logger
private static final int ITERATION_COUNT
private static final int DEFAULT_SALT_LENGTH
private static final byte[] EMPTY_SALT
private static final String OPENSSL_EVP_HEADER_MARKER
private static final int OPENSSL_EVP_HEADER_SIZE
public Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, int keyLength, boolean encryptMode) throws Exception
MD5(password || salt)
].getCipher
in interface PBECipherProvider
encryptionMethod
- the EncryptionMethod
password
- the secret inputsalt
- the saltkeyLength
- the desired key length in bits (ignored because OpenSSL ciphers provide key length in algorithm name)encryptMode
- true for encrypt, false for decryptException
- if there is a problem initializing the cipherpublic Cipher getCipher(EncryptionMethod encryptionMethod, String password, boolean encryptMode) throws Exception
OpenSSLPKCS5CipherProvider#getCipher(EncryptionMethod, String, int, boolean)
encryptionMethod
- the EncryptionMethod
password
- the secret inputencryptMode
- true for encrypt, false for decryptException
- if there is a problem initializing the cipherpublic Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, boolean encryptMode) throws Exception
getCipher(EncryptionMethod, String, byte[], int, boolean)
encryptionMethod
- the EncryptionMethod
password
- the secret inputsalt
- the saltencryptMode
- true for encrypt, false for decryptException
- if there is a problem initializing the cipherprotected Cipher getInitializedCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, boolean encryptMode) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
protected void validateSalt(EncryptionMethod encryptionMethod, byte[] salt)
protected int getIterationCount()
public byte[] generateSalt()
PBECipherProvider
generateSalt
in interface PBECipherProvider
PBECipherProvider.getDefaultSaltLength()
public int getDefaultSaltLength()
PBECipherProvider
getDefaultSaltLength
in interface PBECipherProvider
public byte[] readSalt(InputStream in) throws IOException
readSalt
in interface PBECipherProvider
in
- the cipher InputStreamIOException
public void writeSalt(byte[] salt, OutputStream out) throws IOException
PBECipherProvider
writeSalt
in interface PBECipherProvider
salt
- the saltout
- the cipher OutputStreamIOException
Copyright © 2021 Apache NiFi Project. All rights reserved.