public final class SymmetricAlgorithmBuilder extends Object
GenericEncryptionAlgorithm.
For all supported symmetric ciphers we use initialization vector so we have it also in this builder even if
symmetric ciphers can be without IV by definition. If we would support other ciphers that does not have IV, this
builder should be refactored into two different classes.GenericEncryptionAlgorithm| Constructor and Description |
|---|
SymmetricAlgorithmBuilder(EncryptionFactories factories,
SymmetricEncryptionEngineFactory<ByteArray> engineFactory,
int keySize,
int blockSize)
Creates a new builder.
|
| Modifier and Type | Method and Description |
|---|---|
StreamingEncryptionAlgorithm |
build()
Builds a new instance of encryption algorithm.
|
SymmetricAlgorithmBuilder |
bytesRepresentation(BytesRepresentation bytesRepresentation)
Sets how byte arrays will be represented in strings.
|
SymmetricAlgorithmBuilder |
encoding(String encoding)
Sets encoding for strings in input and output.
|
SymmetricAlgorithmBuilder |
engineFactory(SymmetricEncryptionEngineFactory<ByteArray> engineFactory)
Sets factory for encryption engine.
|
SymmetricAlgorithmBuilder |
ivAndOutputCombining(CombiningSplitting ivOutputCombining)
Sets algorithm combining initialization vector and cipher text in output during encryption
and splitting from input during decryption.
|
SymmetricAlgorithmBuilder |
ivFactory(ByteArrayFactory ivFactory)
Sets algorithm for generation of initialization vector for every message.
|
SymmetricAlgorithmBuilder |
key(byte[] key)
Set custom key.
|
SymmetricAlgorithmBuilder |
keyDerivation(byte[] keyPassword,
byte[] keySalt,
int keyHashIterations)
Sets all parameters for key derivation function.
|
SymmetricAlgorithmBuilder |
keyFactory(EncryptionKeyFactory<ByteArray,DerivedKeyParams> keyFactory)
Sets a custom key factory.
|
SymmetricAlgorithmBuilder |
keyHashIterations(int keyHashIterations)
Sets number of iterations of hashing for key derivation.
|
SymmetricAlgorithmBuilder |
keyPassword(byte[] keyPassword)
Sets a key password for key derivation.
|
SymmetricAlgorithmBuilder |
keyPassword(String keyPassword)
Sets a key password for key derivation.
|
SymmetricAlgorithmBuilder |
keySalt(byte[] keySalt)
Sets salt for key derivation.
|
SymmetricAlgorithmBuilder |
keySalt(String keySalt)
Sets salt for key derivation.
|
public SymmetricAlgorithmBuilder(EncryptionFactories factories, SymmetricEncryptionEngineFactory<ByteArray> engineFactory, int keySize, int blockSize)
factories - factories for enginesengineFactory - factory for encryption enginekeySize - size of the key (in bits)blockSize - size of the block (in bits)public SymmetricAlgorithmBuilder engineFactory(SymmetricEncryptionEngineFactory<ByteArray> engineFactory) throws IllegalArgumentException
engineFactory - factory for encryption engineIllegalArgumentException - exception if passed factory is nullpublic SymmetricAlgorithmBuilder key(byte[] key) throws IllegalArgumentException
Set custom key. Note that client is responsible for correct key size.
If passed key size is invalid, IllegalArgumentException is thrown.
Note that if you use this method, it overrides previous setting of
keyFactory(EncryptionKeyFactory) and keyPassword(byte[]).
key - key to be setIllegalArgumentException - exception if passed key is null or key size is invalidpublic SymmetricAlgorithmBuilder keyPassword(byte[] keyPassword) throws IllegalArgumentException
Sets a key password for key derivation.
Note that if you use this method, it overrides previous setting of key(byte[]).
keyPassword - key password for key derivationIllegalArgumentException - exception if passed key password is nullpublic SymmetricAlgorithmBuilder keyPassword(String keyPassword) throws IllegalArgumentException
Sets a key password for key derivation.
Note that if you use this method, it overrides previous setting of key(byte[]).
keyPassword - key password for key derivationIllegalArgumentException - exception if passed key password is nullpublic SymmetricAlgorithmBuilder keySalt(byte[] keySalt) throws IllegalArgumentException
keySalt - salt to be setIllegalArgumentException - exception if passed key salt is nullpublic SymmetricAlgorithmBuilder keySalt(String keySalt) throws IllegalArgumentException
keySalt - salt to be setIllegalArgumentException - exception if passed key salt is nullpublic SymmetricAlgorithmBuilder keyHashIterations(int keyHashIterations) throws IllegalArgumentException
keyHashIterations - number of hash iterationsIllegalArgumentException - exception if passed iterations are lower than 1public SymmetricAlgorithmBuilder keyDerivation(byte[] keyPassword, byte[] keySalt, int keyHashIterations) throws IllegalArgumentException
Sets all parameters for key derivation function.
Note that if you use this method, it overrides previous setting of key(byte[]).
keyPassword - key password for key derivationkeySalt - salt for key derivationkeyHashIterations - number of hash iterationsIllegalArgumentException - exception if passed key password is nullpublic SymmetricAlgorithmBuilder keyFactory(EncryptionKeyFactory<ByteArray,DerivedKeyParams> keyFactory) throws IllegalArgumentException
Sets a custom key factory.
Note that if you use this method, it overrides previous setting of key(byte[]).
keyFactory - factory to be setIllegalArgumentException - exception if passed factory is nullpublic SymmetricAlgorithmBuilder ivFactory(ByteArrayFactory ivFactory) throws IllegalArgumentException
ivAndOutputCombining(CombiningSplitting) into the final output.ivFactory - factory for initialization vectorIllegalArgumentException - exception if passed ByteArrayFactory is nullpublic SymmetricAlgorithmBuilder ivAndOutputCombining(CombiningSplitting ivOutputCombining) throws IllegalArgumentException
ivOutputCombining - combine/split algorithm for IV and cipher textIllegalArgumentException - exception if passed CombiningSplitting is nullpublic SymmetricAlgorithmBuilder bytesRepresentation(BytesRepresentation bytesRepresentation) throws IllegalArgumentException
HexRepresentation is used.bytesRepresentation - byte array representation strategyIllegalArgumentException - exception if passed BytesRepresentation is nullpublic SymmetricAlgorithmBuilder encoding(String encoding) throws IllegalArgumentException
encoding - encoding to be setIllegalArgumentException - exception if given encoding is null or not supportedpublic StreamingEncryptionAlgorithm build() throws IllegalArgumentException
IllegalArgumentExceptionCopyright © 2019. All rights reserved.