Class EncryptionConfig

java.lang.Object
com.tnsai.quality.security.EncryptionConfig

public final class EncryptionConfig extends Object
Configuration for AES-256-GCM encryption used by SecurityEnforcer.

This class manages encryption keys and provides configuration options for the encryption algorithm. It supports:

  • AES-256-GCM authenticated encryption
  • Secure key generation
  • Key import/export via Base64
  • Configurable IV (Initialization Vector) length
  • Configurable authentication tag length

Usage


 // Generate new key
 EncryptionConfig config = EncryptionConfig.generateKey();

 // Import existing key
 EncryptionConfig config = EncryptionConfig.fromBase64Key(base64Key);

 // Use with SecurityEnforcer
 SecurityEnforcer enforcer = new SecurityEnforcer(config);
 
Author:
TnsAI Team
  • Field Details

  • Method Details

    • generateKey

      public static EncryptionConfig generateKey()
      Generates a new EncryptionConfig with a randomly generated AES-256 key.
      Returns:
      new EncryptionConfig with generated key
      Throws:
      SecurityException - if key generation fails
    • fromBase64Key

      public static EncryptionConfig fromBase64Key(String base64Key)
      Creates an EncryptionConfig from a Base64-encoded key.
      Parameters:
      base64Key - the Base64-encoded AES-256 key
      Returns:
      new EncryptionConfig with the provided key
      Throws:
      IllegalArgumentException - if the key is invalid
    • fromKeyBytes

      public static EncryptionConfig fromKeyBytes(byte[] keyBytes)
      Creates an EncryptionConfig from raw key bytes.
      Parameters:
      keyBytes - the raw AES-256 key bytes (32 bytes)
      Returns:
      new EncryptionConfig with the provided key
      Throws:
      IllegalArgumentException - if the key is invalid
    • builder

      public static EncryptionConfig.Builder builder()
      Creates a builder for custom EncryptionConfig.
      Returns:
      new Builder instance
    • getSecretKey

      public SecretKey getSecretKey()
      Gets the secret key.
      Returns:
      the AES secret key
    • getIvLengthBytes

      public int getIvLengthBytes()
      Gets the IV (Initialization Vector) length in bytes.
      Returns:
      IV length in bytes
    • getTagLengthBits

      public int getTagLengthBits()
      Gets the authentication tag length in bits.
      Returns:
      tag length in bits
    • getSecureRandom

      public SecureRandom getSecureRandom()
      Gets the SecureRandom instance for generating IVs.
      Returns:
      SecureRandom instance
    • generateIv

      public byte[] generateIv()
      Generates a new random IV.
      Returns:
      random IV bytes
    • toBase64Key

      public String toBase64Key()
      Exports the key as a Base64-encoded string.
      Returns:
      Base64-encoded key