java.lang.Object
dev.orne.config.impl.AbstractConfigCryptoEngine
dev.orne.config.impl.ConfigCryptoAesGcmEngine
- All Implemented Interfaces:
ConfigCryptoEngine
@API(status=INTERNAL,
since="1.0")
public class ConfigCryptoAesGcmEngine
extends AbstractConfigCryptoEngine
Implementation of
ConfigCryptoEngine based on
Java Cryptography Architecture using AES with GCM symmetric algorithm.- Since:
- 0.2
- Version:
- 1.0, 2020-08
- Author:
- (w) Iker Hernaez
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe defaultCipheralgorithm.static final intThe default GCM initial vector length.static final intThe default GCM tag length.static final StringThe defaultSecretKeyalgorithm.static final StringThe defaultSecretKeyFactoryalgorithm.static final intThe defaultSecretKeysalt iterations.static final intThe defaultSecretKeylength.Fields inherited from class dev.orne.config.impl.AbstractConfigCryptoEngine
DEFAULT_SECRET_KEY_SALT_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionConfigCryptoAesGcmEngine(@javax.validation.constraints.NotNull byte[] secretKeySalt) Creates a new instance with the defaultSecretKeyFactory,SecretKeyandCipheralgorithms.ConfigCryptoAesGcmEngine(@NotNull String secretKeyFactoryAlgorithm, @NotNull String secretKeyAlgorithm, @javax.validation.constraints.NotNull byte[] secretKeySalt, @NotNull String cipherAlgorithm) Creates a new instance with the specifiedSecretKeyFactory,SecretKeyandCipheralgorithms. -
Method Summary
Modifier and TypeMethodDescription@NotNull CipherCreates a newCipherfor this engine.protected @NotNull KeySpeccreateKeySpec(@javax.validation.constraints.NotNull char[] password) Generates the secret key specification for the specified password and the@NotNull SecretKeycreateSecretKey(@javax.validation.constraints.NotNull char[] password) Creates a newSecretKeyfor this engine for the specified password.@NotNull StringDecrypts the specified encrypted configuration value.voiddestroy()Destroys all secret information.@NotNull StringEncrypts the specified plain configuration value.@NotNull StringReturns theCipheralgorithm.intReturns the GCM initial vector length.intReturns the GCM tag length.@NotNull StringReturns theSecretKeyalgorithm.@NotNull StringReturns theSecretKeyFactoryalgorithm.intReturns theSecretKeysalt iterations.intReturns the generatedSecretKeylength.voidsetGcmInitVectorLength(int length) Sets the GCM initial vector length.voidsetGcmTagLength(int length) Sets the GCM tag length.voidsetSecretKeyIterations(int iterations) Sets the generatedSecretKeysalt iterations.voidsetSecretKeyLength(int length) Sets the generatedSecretKeylength.Methods inherited from class dev.orne.config.impl.AbstractConfigCryptoEngine
checkDestroyed, createCipher, createSecureRandom, getSecretKeyFactory, getSecureRandom, isDestroyed, setSecureRandom
-
Field Details
-
DEFAULT_KEY_FACTORY_ALGORITHM
The defaultSecretKeyFactoryalgorithm.- See Also:
-
DEFAULT_KEY_ALGORITHM
The defaultSecretKeyalgorithm.- See Also:
-
DEFAULT_CIPHER_ALGORITHM
The defaultCipheralgorithm.- See Also:
-
DEFAULT_SECRET_KEY_ITERATIONS
public static final int DEFAULT_SECRET_KEY_ITERATIONSThe defaultSecretKeysalt iterations.- See Also:
-
DEFAULT_SECRET_KEY_LENGTH
public static final int DEFAULT_SECRET_KEY_LENGTHThe defaultSecretKeylength.- See Also:
-
DEFAULT_GCM_IV_LENGTH
public static final int DEFAULT_GCM_IV_LENGTHThe default GCM initial vector length.- See Also:
-
DEFAULT_GCM_TAG_LENGTH
public static final int DEFAULT_GCM_TAG_LENGTHThe default GCM tag length.- See Also:
-
-
Constructor Details
-
ConfigCryptoAesGcmEngine
public ConfigCryptoAesGcmEngine(@NotNull @javax.validation.constraints.NotNull byte[] secretKeySalt) Creates a new instance with the defaultSecretKeyFactory,SecretKeyandCipheralgorithms.- Parameters:
secretKeySalt- The salt used for theSecretKeycreations.
-
ConfigCryptoAesGcmEngine
public ConfigCryptoAesGcmEngine(@NotNull @NotNull String secretKeyFactoryAlgorithm, @NotNull @NotNull String secretKeyAlgorithm, @NotNull @javax.validation.constraints.NotNull byte[] secretKeySalt, @NotNull @NotNull String cipherAlgorithm) Creates a new instance with the specifiedSecretKeyFactory,SecretKeyandCipheralgorithms.- Parameters:
secretKeyFactoryAlgorithm- TheSecretKeyFactoryalgorithmsecretKeyAlgorithm- TheSecretKeyalgorithmsecretKeySalt- The salt used for theSecretKeycreations.cipherAlgorithm- TheCipheralgorithm
-
-
Method Details
-
getSecretKeyFactoryAlgorithm
Returns theSecretKeyFactoryalgorithm.- Returns:
- The
SecretKeyFactoryalgorithm.
-
getSecretKeyIterations
public int getSecretKeyIterations()Returns theSecretKeysalt iterations.- Returns:
- The
SecretKeysalt iterations
-
setSecretKeyIterations
public void setSecretKeyIterations(int iterations) Sets the generatedSecretKeysalt iterations.- Parameters:
iterations- The generatedSecretKeysalt iterations
-
getSecretKeyLength
public int getSecretKeyLength()Returns the generatedSecretKeylength.- Returns:
- The generated
SecretKeylength
-
setSecretKeyLength
public void setSecretKeyLength(int length) Sets the generatedSecretKeylength.- Parameters:
length- The generatedSecretKeylength
-
getSecretKeyAlgorithm
Returns theSecretKeyalgorithm.- Returns:
- The
SecretKeyalgorithm
-
getCipherAlgorithm
Returns theCipheralgorithm.- Returns:
- The
Cipheralgorithm
-
getGcmInitVectorLength
public int getGcmInitVectorLength()Returns the GCM initial vector length.- Returns:
- The GCM initial vector length
-
setGcmInitVectorLength
public void setGcmInitVectorLength(int length) Sets the GCM initial vector length.- Parameters:
length- The GCM initial vector length
-
getGcmTagLength
public int getGcmTagLength()Returns the GCM tag length.- Returns:
- The GCM tag length
-
setGcmTagLength
public void setGcmTagLength(int length) Sets the GCM tag length.- Parameters:
length- The GCM tag length
-
createSecretKey
@NotNull public @NotNull SecretKey createSecretKey(@NotNull @javax.validation.constraints.NotNull char[] password) throws ConfigCryptoProviderException Creates a newSecretKeyfor this engine for the specified password.- Parameters:
password- The password- Returns:
- The newly created
SecretKey - Throws:
ConfigCryptoProviderException- If an exception occurs creating theSecretKey
-
createKeySpec
@NotNull protected @NotNull KeySpec createKeySpec(@NotNull @javax.validation.constraints.NotNull char[] password) throws ConfigCryptoProviderException Generates the secret key specification for the specified password and the- Parameters:
password- The password- Returns:
- The secret key specification
- Throws:
ConfigCryptoProviderException- If an error occurs when creating the specification
-
createCipher
Creates a newCipherfor this engine.- Returns:
- The newly created
Cipher - Throws:
ConfigCryptoProviderException- If an exception occurs creating theCipher
-
encrypt
@NotNull public @NotNull String encrypt(@NotNull @NotNull String value, @NotNull @NotNull SecretKey key, @NotNull @NotNull Cipher cipher) throws ConfigCryptoProviderException Encrypts the specified plain configuration value.- Parameters:
value- The plain configuration valuekey- TheSecretKeyto usecipher- TheCipherto use- Returns:
- The encrypted configuration value
- Throws:
ConfigCryptoProviderException- If an exception occurs during the encryption process
-
decrypt
@NotNull public @NotNull String decrypt(@NotNull @NotNull String value, @NotNull @NotNull SecretKey key, @NotNull @NotNull Cipher cipher) throws ConfigCryptoProviderException Decrypts the specified encrypted configuration value.- Parameters:
value- The encrypted configuration valuekey- TheSecretKeyto usecipher- TheCipherto use- Returns:
- The plain configuration value
- Throws:
ConfigCryptoProviderException- If an exception occurs during the decryption process
-
destroy
public void destroy()Destroys all secret information. Any further call to the instance will throw anIllegalStateException.- Specified by:
destroyin interfaceConfigCryptoEngine- Overrides:
destroyin classAbstractConfigCryptoEngine
-