Package org.wildfly.security.util
Class PasswordBasedEncryptionUtil.Builder
- java.lang.Object
-
- org.wildfly.security.util.PasswordBasedEncryptionUtil.Builder
-
- Enclosing class:
- PasswordBasedEncryptionUtil
public static class PasswordBasedEncryptionUtil.Builder extends Object
Builder class to buildPasswordBasedEncryptionUtil
class with all necessary parameters to support password based encryption algorithms.
-
-
Field Summary
Fields Modifier and Type Field Description private AlgorithmParameters
algorithmParameters
private org.wildfly.common.codec.Alphabet
alphabet
private int
cipherIteration
private int
cipherMode
private byte[]
cipherSalt
private String
encodedIV
private int
iteration
private IvParameterSpec
ivSpec
private String
keyAlgorithm
private int
keyLength
private String
parametersAlgorithm
private char[]
password
private boolean
picketBoxCompatibility
private Provider
provider
private byte[]
salt
private String
transformation
private boolean
usePadding
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PasswordBasedEncryptionUtil.Builder
algorithmParameters(AlgorithmParameters algorithmParameters)
Set algorithm parameters forCipher
initialization.PasswordBasedEncryptionUtil.Builder
alphabet(org.wildfly.common.codec.Alphabet alphabet)
Set the alphabet to encode/decode result of encryption/decryption.PasswordBasedEncryptionUtil
build()
Builds PBE utility class instancePasswordBasedEncryptionUtil.Builder
cipherIteration(int cipherIteration)
Set the number of iterations forCipher
PasswordBasedEncryptionUtil.Builder
cipherSalt(byte[] cipherSalt)
Set salt for theCipher
PasswordBasedEncryptionUtil.Builder
cipherSalt(String cipherSalt)
Set salt for theCipher
private Cipher
createAndInitCipher(SecretKey secretKey)
PasswordBasedEncryptionUtil.Builder
decryptMode()
Set decryption mode for chosenCipher
private SecretKey
deriveSecretKey()
PasswordBasedEncryptionUtil.Builder
encodingPadded()
Use padding when encoding/decoding binary data.PasswordBasedEncryptionUtil.Builder
encryptMode()
Set encryption mode for chosenCipher
private static AlgorithmParameters
generateAlgorithmParameters(String algorithm, int iterationCount, byte[] salt, IvParameterSpec ivSpec, Provider provider)
PasswordBasedEncryptionUtil.Builder
iteration(int iteration)
Set number of iteration for key derivation.PasswordBasedEncryptionUtil.Builder
iv(byte[] iv)
Set initialization vector for use with AES algorithmsPasswordBasedEncryptionUtil.Builder
iv(String encodedIV)
Set initialization vector for use with AES algorithmsPasswordBasedEncryptionUtil.Builder
keyAlgorithm(String keyAlgorithm)
Set the key derivation algorithm.PasswordBasedEncryptionUtil.Builder
keyLength(int keyLength)
Set the key length.PasswordBasedEncryptionUtil.Builder
parametersAlgorithm(String parametersAlgorithm)
Set the name of parameter's algorithm to initialize theCipher
PasswordBasedEncryptionUtil.Builder
password(char[] password)
Set password to use to generate the encryption keyPasswordBasedEncryptionUtil.Builder
password(String password)
Set password to use to generate the encryption keyPasswordBasedEncryptionUtil.Builder
picketBoxCompatibility()
Use PicketBox compatibility mode for producing exact output as using PBE for MASK- purpose.PasswordBasedEncryptionUtil.Builder
provider(String providerName)
Set the JCA provider name which contains all classes needed by built utility class.PasswordBasedEncryptionUtil.Builder
provider(Provider provider)
Set the JCA provider which contains all classes needed by built utility class.PasswordBasedEncryptionUtil.Builder
salt(byte[] salt)
Set salt for key derivation.PasswordBasedEncryptionUtil.Builder
salt(String salt)
Set salt for key derivation.PasswordBasedEncryptionUtil.Builder
transformation(String transformation)
Transformation name to use asCipher
parameter.
-
-
-
Field Detail
-
keyAlgorithm
private String keyAlgorithm
-
transformation
private String transformation
-
parametersAlgorithm
private String parametersAlgorithm
-
iteration
private int iteration
-
salt
private byte[] salt
-
keyLength
private int keyLength
-
password
private char[] password
-
cipherMode
private int cipherMode
-
cipherIteration
private int cipherIteration
-
cipherSalt
private byte[] cipherSalt
-
provider
private Provider provider
-
alphabet
private org.wildfly.common.codec.Alphabet alphabet
-
usePadding
private boolean usePadding
-
ivSpec
private IvParameterSpec ivSpec
-
encodedIV
private String encodedIV
-
algorithmParameters
private AlgorithmParameters algorithmParameters
-
picketBoxCompatibility
private boolean picketBoxCompatibility
-
-
Method Detail
-
password
public PasswordBasedEncryptionUtil.Builder password(char[] password)
Set password to use to generate the encryption key- Parameters:
password
- the password- Returns:
- this Builder
-
password
public PasswordBasedEncryptionUtil.Builder password(String password)
Set password to use to generate the encryption key- Parameters:
password
- the password- Returns:
- this Builder
-
iv
public PasswordBasedEncryptionUtil.Builder iv(byte[] iv)
Set initialization vector for use with AES algorithms- Parameters:
iv
- the raw IV- Returns:
- this Builder
-
iv
public PasswordBasedEncryptionUtil.Builder iv(String encodedIV)
Set initialization vector for use with AES algorithms- Parameters:
encodedIV
- IV encoded usingAlphabet
set in this builder (or default)- Returns:
- this Builder
-
transformation
public PasswordBasedEncryptionUtil.Builder transformation(String transformation)
Transformation name to use asCipher
parameter.- Parameters:
transformation
- the name of transformation- Returns:
- this Builder
-
parametersAlgorithm
public PasswordBasedEncryptionUtil.Builder parametersAlgorithm(String parametersAlgorithm)
Set the name of parameter's algorithm to initialize theCipher
- Parameters:
parametersAlgorithm
- the name of parameter's algorithm- Returns:
- this Builder
-
salt
public PasswordBasedEncryptionUtil.Builder salt(String salt)
Set salt for key derivation.- Parameters:
salt
- the salt- Returns:
- this Builder
-
salt
public PasswordBasedEncryptionUtil.Builder salt(byte[] salt)
Set salt for key derivation.- Parameters:
salt
- the salt- Returns:
- this Builder
-
picketBoxCompatibility
public PasswordBasedEncryptionUtil.Builder picketBoxCompatibility()
Use PicketBox compatibility mode for producing exact output as using PBE for MASK- purpose. Problem is that PicketBox is using different base64 than standard. Default isfalse
.- Returns:
- this Builder
-
encodingPadded
public PasswordBasedEncryptionUtil.Builder encodingPadded()
Use padding when encoding/decoding binary data.- Returns:
- this Builder
-
iteration
public PasswordBasedEncryptionUtil.Builder iteration(int iteration)
Set number of iteration for key derivation.- Parameters:
iteration
- the number of iterations- Returns:
- this Builder
-
keyAlgorithm
public PasswordBasedEncryptionUtil.Builder keyAlgorithm(String keyAlgorithm)
Set the key derivation algorithm.- Parameters:
keyAlgorithm
- the algorithm- Returns:
- this Builder
-
keyLength
public PasswordBasedEncryptionUtil.Builder keyLength(int keyLength)
Set the key length.- Parameters:
keyLength
- the length- Returns:
- this Builder
-
cipherIteration
public PasswordBasedEncryptionUtil.Builder cipherIteration(int cipherIteration)
Set the number of iterations forCipher
- Parameters:
cipherIteration
- number of iterations- Returns:
- this Builder
-
cipherSalt
public PasswordBasedEncryptionUtil.Builder cipherSalt(byte[] cipherSalt)
Set salt for theCipher
- Parameters:
cipherSalt
- the salt- Returns:
- this Builder
-
cipherSalt
public PasswordBasedEncryptionUtil.Builder cipherSalt(String cipherSalt)
Set salt for theCipher
- Parameters:
cipherSalt
- the salt- Returns:
- this Builder
-
provider
public PasswordBasedEncryptionUtil.Builder provider(Provider provider)
Set the JCA provider which contains all classes needed by built utility class.- Parameters:
provider
- the provider- Returns:
- this Builder
-
provider
public PasswordBasedEncryptionUtil.Builder provider(String providerName)
Set the JCA provider name which contains all classes needed by built utility class.- Parameters:
providerName
- the provider name- Returns:
- this Builder
-
alphabet
public PasswordBasedEncryptionUtil.Builder alphabet(org.wildfly.common.codec.Alphabet alphabet)
Set the alphabet to encode/decode result of encryption/decryption.- Parameters:
alphabet
- theAlphabet
instance- Returns:
- this Builder
-
encryptMode
public PasswordBasedEncryptionUtil.Builder encryptMode()
Set encryption mode for chosenCipher
- Returns:
- this Builder
-
decryptMode
public PasswordBasedEncryptionUtil.Builder decryptMode()
Set decryption mode for chosenCipher
- Returns:
- this Builder
-
algorithmParameters
public PasswordBasedEncryptionUtil.Builder algorithmParameters(AlgorithmParameters algorithmParameters)
Set algorithm parameters forCipher
initialization.- Parameters:
algorithmParameters
- the algorithm parameters instance in form required by the usedCipher
- Returns:
- this Builder
-
createAndInitCipher
private Cipher createAndInitCipher(SecretKey secretKey) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
generateAlgorithmParameters
private static AlgorithmParameters generateAlgorithmParameters(String algorithm, int iterationCount, byte[] salt, IvParameterSpec ivSpec, Provider provider) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
deriveSecretKey
private SecretKey deriveSecretKey() throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
build
public PasswordBasedEncryptionUtil build() throws GeneralSecurityException
Builds PBE utility class instance- Returns:
- PBE utility class instance
PasswordBasedEncryptionUtil
- Throws:
GeneralSecurityException
- when something goes wrong while initializing encryption related objects
-
-