Package com.tnsai.quality.security
Class EncryptionConfig
java.lang.Object
com.tnsai.quality.security.EncryptionConfig
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creating EncryptionConfig with custom settings. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic EncryptionConfig.Builderbuilder()Creates a builder for custom EncryptionConfig.static EncryptionConfigfromBase64Key(String base64Key) Creates an EncryptionConfig from a Base64-encoded key.static EncryptionConfigfromKeyBytes(byte[] keyBytes) Creates an EncryptionConfig from raw key bytes.byte[]Generates a new random IV.static EncryptionConfigGenerates a new EncryptionConfig with a randomly generated AES-256 key.intGets the IV (Initialization Vector) length in bytes.Gets the secret key.Gets the SecureRandom instance for generating IVs.intGets the authentication tag length in bits.Exports the key as a Base64-encoded string.
-
Field Details
-
ALGORITHM
- See Also:
-
TRANSFORMATION
- See Also:
-
KEY_SIZE_BITS
public static final int KEY_SIZE_BITS- See Also:
-
DEFAULT_IV_LENGTH_BYTES
public static final int DEFAULT_IV_LENGTH_BYTES- See Also:
-
DEFAULT_TAG_LENGTH_BITS
public static final int DEFAULT_TAG_LENGTH_BITS- See Also:
-
-
Method Details
-
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
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
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
Creates a builder for custom EncryptionConfig.- Returns:
- new Builder instance
-
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
Gets the SecureRandom instance for generating IVs.- Returns:
- SecureRandom instance
-
generateIv
public byte[] generateIv()Generates a new random IV.- Returns:
- random IV bytes
-
toBase64Key
Exports the key as a Base64-encoded string.- Returns:
- Base64-encoded key
-