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 buildPasswordBasedEncryptionUtilclass with all necessary parameters to support password based encryption algorithms.
-
-
Field Summary
Fields Modifier and Type Field Description private AlgorithmParametersalgorithmParametersprivate org.wildfly.common.codec.Alphabetalphabetprivate intcipherIterationprivate intcipherModeprivate byte[]cipherSaltprivate StringencodedIVprivate intiterationprivate IvParameterSpecivSpecprivate StringkeyAlgorithmprivate intkeyLengthprivate StringparametersAlgorithmprivate char[]passwordprivate booleanpicketBoxCompatibilityprivate Providerproviderprivate byte[]saltprivate Stringtransformationprivate booleanusePadding
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PasswordBasedEncryptionUtil.BuilderalgorithmParameters(AlgorithmParameters algorithmParameters)Set algorithm parameters forCipherinitialization.PasswordBasedEncryptionUtil.Builderalphabet(org.wildfly.common.codec.Alphabet alphabet)Set the alphabet to encode/decode result of encryption/decryption.PasswordBasedEncryptionUtilbuild()Builds PBE utility class instancePasswordBasedEncryptionUtil.BuildercipherIteration(int cipherIteration)Set the number of iterations forCipherPasswordBasedEncryptionUtil.BuildercipherSalt(byte[] cipherSalt)Set salt for theCipherPasswordBasedEncryptionUtil.BuildercipherSalt(String cipherSalt)Set salt for theCipherprivate CiphercreateAndInitCipher(SecretKey secretKey)PasswordBasedEncryptionUtil.BuilderdecryptMode()Set decryption mode for chosenCipherprivate SecretKeyderiveSecretKey()PasswordBasedEncryptionUtil.BuilderencodingPadded()Use padding when encoding/decoding binary data.PasswordBasedEncryptionUtil.BuilderencryptMode()Set encryption mode for chosenCipherprivate static AlgorithmParametersgenerateAlgorithmParameters(String algorithm, int iterationCount, byte[] salt, IvParameterSpec ivSpec, Provider provider)PasswordBasedEncryptionUtil.Builderiteration(int iteration)Set number of iteration for key derivation.PasswordBasedEncryptionUtil.Builderiv(byte[] iv)Set initialization vector for use with AES algorithmsPasswordBasedEncryptionUtil.Builderiv(String encodedIV)Set initialization vector for use with AES algorithmsPasswordBasedEncryptionUtil.BuilderkeyAlgorithm(String keyAlgorithm)Set the key derivation algorithm.PasswordBasedEncryptionUtil.BuilderkeyLength(int keyLength)Set the key length.PasswordBasedEncryptionUtil.BuilderparametersAlgorithm(String parametersAlgorithm)Set the name of parameter's algorithm to initialize theCipherPasswordBasedEncryptionUtil.Builderpassword(char[] password)Set password to use to generate the encryption keyPasswordBasedEncryptionUtil.Builderpassword(String password)Set password to use to generate the encryption keyPasswordBasedEncryptionUtil.BuilderpicketBoxCompatibility()Use PicketBox compatibility mode for producing exact output as using PBE for MASK- purpose.PasswordBasedEncryptionUtil.Builderprovider(String providerName)Set the JCA provider name which contains all classes needed by built utility class.PasswordBasedEncryptionUtil.Builderprovider(Provider provider)Set the JCA provider which contains all classes needed by built utility class.PasswordBasedEncryptionUtil.Buildersalt(byte[] salt)Set salt for key derivation.PasswordBasedEncryptionUtil.Buildersalt(String salt)Set salt for key derivation.PasswordBasedEncryptionUtil.Buildertransformation(String transformation)Transformation name to use asCipherparameter.
-
-
-
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 usingAlphabetset in this builder (or default)- Returns:
- this Builder
-
transformation
public PasswordBasedEncryptionUtil.Builder transformation(String transformation)
Transformation name to use asCipherparameter.- 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- theAlphabetinstance- 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 forCipherinitialization.- 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
-
-