Class AesEncryptionProvider

  • All Implemented Interfaces:
    EncryptionProvider

    public class AesEncryptionProvider
    extends Object
    implements EncryptionProvider
    AES-256-GCM encryption provider for secure configuration values.

    This provider uses AES-256 in GCM mode, which provides both confidentiality and authenticity. The IV is prepended to the ciphertext for storage.

    Example Usage:

    
     // Create provider with a 256-bit key
     byte[] keyBytes = ... // 32 bytes for AES-256
     AesEncryptionProvider provider = new AesEncryptionProvider(keyBytes);
     
     // Or from Base64 encoded key
     AesEncryptionProvider provider = AesEncryptionProvider.fromBase64Key("base64EncodedKey");
     
     // Or from environment variable
     AesEncryptionProvider provider = AesEncryptionProvider.fromEnvironment();
     
     // Register with ConfNG
     ConfNG.setEncryptionProvider(provider);
     
    Since:
    1.1.0
    Author:
    Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
    • Constructor Detail

      • AesEncryptionProvider

        public AesEncryptionProvider​(byte[] keyBytes)
        Creates a new AES encryption provider with the given key bytes.
        Parameters:
        keyBytes - the AES key (must be 16, 24, or 32 bytes for AES-128/192/256)
      • AesEncryptionProvider

        public AesEncryptionProvider​(SecretKey secretKey)
        Creates a new AES encryption provider with the given SecretKey.
        Parameters:
        secretKey - the AES secret key
    • Method Detail

      • fromBase64Key

        public static AesEncryptionProvider fromBase64Key​(String base64Key)
        Creates an AES encryption provider from a Base64-encoded key.
        Parameters:
        base64Key - the Base64-encoded key
        Returns:
        the encryption provider
      • fromEnvironment

        public static AesEncryptionProvider fromEnvironment()
        Creates an AES encryption provider from the CONFNG_ENCRYPTION_KEY environment variable.
        Returns:
        the encryption provider
        Throws:
        EncryptionException - if the environment variable is not set
      • fromProperty

        public static AesEncryptionProvider fromProperty​(String propertyName)
        Creates an AES encryption provider from a system property or environment variable.
        Parameters:
        propertyName - the system property or environment variable name
        Returns:
        the encryption provider