Interface EncryptionProvider

  • All Known Implementing Classes:
    AesEncryptionProvider

    public interface EncryptionProvider
    Interface for encryption/decryption providers.

    Implement this interface to provide custom encryption/decryption logic for configuration values marked with Encrypted.

    Example Implementation:

    {@code
     public class MyEncryptionProvider implements EncryptionProvider {
         private final SecretKey key;
         
         public MyEncryptionProvider(String keyBase64) {
             byte[] keyBytes = Base64.getDecoder().decode(keyBase64);
             this.key = new SecretKeySpec(keyBytes, "AES");
         }
    Since:
    1.1.0
    Author:
    Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
    See Also:
    Encrypted, AesEncryptionProvider
    • Method Detail

      • decrypt

        String decrypt​(String encryptedValue)
                throws EncryptionException
        Decrypts an encrypted value.
        Parameters:
        encryptedValue - the encrypted value (typically Base64 encoded)
        Returns:
        the decrypted plain text value
        Throws:
        EncryptionException - if decryption fails
      • encrypt

        String encrypt​(String plainValue)
                throws EncryptionException
        Encrypts a plain text value.
        Parameters:
        plainValue - the plain text value to encrypt
        Returns:
        the encrypted value (typically Base64 encoded)
        Throws:
        EncryptionException - if encryption fails
      • getName

        default String getName()
        Gets the name of this encryption provider.
        Returns:
        the provider name
      • isEncrypted

        default boolean isEncrypted​(String value)
        Checks if a value appears to be encrypted.

        The default implementation checks for common encrypted value prefixes like "ENC(" or "{cipher}".

        Parameters:
        value - the value to check
        Returns:
        true if the value appears to be encrypted
      • extractPayload

        default String extractPayload​(String wrappedValue)
        Extracts the encrypted payload from a wrapped value.

        For example, extracts "abc123" from "ENC(abc123)".

        Parameters:
        wrappedValue - the wrapped encrypted value
        Returns:
        the extracted payload