Class EncryptionManager


  • public class EncryptionManager
    extends Object
    Manages encryption providers and handles decryption of configuration values.
    Since:
    1.1.0
    Author:
    Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
    • Method Detail

      • getInstance

        public static EncryptionManager getInstance()
        Gets the singleton instance.
      • setDefaultProvider

        public void setDefaultProvider​(EncryptionProvider provider)
        Sets the default encryption provider.
      • getDefaultProvider

        public EncryptionProvider getDefaultProvider()
        Gets the default encryption provider.
      • registerProvider

        public void registerProvider​(String name,
                                     EncryptionProvider provider)
        Registers a named encryption provider.
      • decryptIfNeeded

        public String decryptIfNeeded​(ConfNGKey key,
                                      String value)
        Decrypts a value if it appears to be encrypted and the key is marked with @Encrypted.
        Parameters:
        key - the configuration key
        value - the value to potentially decrypt
        Returns:
        the decrypted value, or the original value if not encrypted
      • decryptValue

        public String decryptValue​(String value,
                                   EncryptionProvider provider,
                                   boolean failOnError)
        Decrypts a value using the specified provider.
      • encrypt

        public String encrypt​(String plainValue)
        Encrypts a value using the default provider.
      • encrypt

        public String encrypt​(String plainValue,
                              String providerName)
        Encrypts a value using a named provider.
      • reset

        public static void reset()
        Resets the singleton instance. Useful for testing.