Class ConfigCryptoAesGcmEngine

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 Details

    • DEFAULT_KEY_FACTORY_ALGORITHM

      public static final String DEFAULT_KEY_FACTORY_ALGORITHM
      The default SecretKeyFactory algorithm.
      See Also:
    • DEFAULT_KEY_ALGORITHM

      public static final String DEFAULT_KEY_ALGORITHM
      The default SecretKey algorithm.
      See Also:
    • DEFAULT_CIPHER_ALGORITHM

      public static final String DEFAULT_CIPHER_ALGORITHM
      The default Cipher algorithm.
      See Also:
    • DEFAULT_SECRET_KEY_ITERATIONS

      public static final int DEFAULT_SECRET_KEY_ITERATIONS
      The default SecretKey salt iterations.
      See Also:
    • DEFAULT_SECRET_KEY_LENGTH

      public static final int DEFAULT_SECRET_KEY_LENGTH
      The default SecretKey length.
      See Also:
    • DEFAULT_GCM_IV_LENGTH

      public static final int DEFAULT_GCM_IV_LENGTH
      The default GCM initial vector length.
      See Also:
    • DEFAULT_GCM_TAG_LENGTH

      public static final int DEFAULT_GCM_TAG_LENGTH
      The default GCM tag length.
      See Also:
  • Constructor Details

    • ConfigCryptoAesGcmEngine

      public ConfigCryptoAesGcmEngine(@NotNull @javax.validation.constraints.NotNull byte[] secretKeySalt)
      Creates a new instance with the default SecretKeyFactory, SecretKey and Cipher algorithms.
      Parameters:
      secretKeySalt - The salt used for the SecretKey creations.
    • 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 specified SecretKeyFactory, SecretKey and Cipher algorithms.
      Parameters:
      secretKeyFactoryAlgorithm - The SecretKeyFactory algorithm
      secretKeyAlgorithm - The SecretKey algorithm
      secretKeySalt - The salt used for the SecretKey creations.
      cipherAlgorithm - The Cipher algorithm
  • Method Details

    • getSecretKeyFactoryAlgorithm

      @NotNull public @NotNull String getSecretKeyFactoryAlgorithm()
      Returns the SecretKeyFactory algorithm.
      Returns:
      The SecretKeyFactory algorithm.
    • getSecretKeyIterations

      public int getSecretKeyIterations()
      Returns the SecretKey salt iterations.
      Returns:
      The SecretKey salt iterations
    • setSecretKeyIterations

      public void setSecretKeyIterations(int iterations)
      Sets the generated SecretKey salt iterations.
      Parameters:
      iterations - The generated SecretKey salt iterations
    • getSecretKeyLength

      public int getSecretKeyLength()
      Returns the generated SecretKey length.
      Returns:
      The generated SecretKey length
    • setSecretKeyLength

      public void setSecretKeyLength(int length)
      Sets the generated SecretKey length.
      Parameters:
      length - The generated SecretKey length
    • getSecretKeyAlgorithm

      @NotNull public @NotNull String getSecretKeyAlgorithm()
      Returns the SecretKey algorithm.
      Returns:
      The SecretKey algorithm
    • getCipherAlgorithm

      @NotNull public @NotNull String getCipherAlgorithm()
      Returns the Cipher algorithm.
      Returns:
      The Cipher algorithm
    • 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 new SecretKey for this engine for the specified password.
      Parameters:
      password - The password
      Returns:
      The newly created SecretKey
      Throws:
      ConfigCryptoProviderException - If an exception occurs creating the SecretKey
    • 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

      @NotNull public @NotNull Cipher createCipher() throws ConfigCryptoProviderException
      Creates a new Cipher for this engine.
      Returns:
      The newly created Cipher
      Throws:
      ConfigCryptoProviderException - If an exception occurs creating the Cipher
    • 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 value
      key - The SecretKey to use
      cipher - The Cipher to 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 value
      key - The SecretKey to use
      cipher - The Cipher to 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 an IllegalStateException.
      Specified by:
      destroy in interface ConfigCryptoEngine
      Overrides:
      destroy in class AbstractConfigCryptoEngine