Class EncryptionProvider


  • public abstract class EncryptionProvider
    extends Object
    Provides basic facilities to encrypt and decrypt content. This implementation relies on algorithms provided by javax.crypto.Cipher.

    Note that clients are strongly recommended to use HTTPS instead of HTTP to secure communications, in which case this class is useless.

    See Also:
    Cipher
    • Constructor Detail

      • EncryptionProvider

        public EncryptionProvider()
    • Method Detail

      • getInstance

        public static EncryptionProvider getInstance​(String algorithm,
                                                     String iv)
                                              throws CoreException
        Instantiates an EncryptionProvider for the specified cipher algorithm and initialization vector. If the algorithm is null or an empty String, the returned instance will not encrypt nor decrypt provided content.
        Parameters:
        algorithm - the cipher algorithm.
        iv - the cipher initialization vector.
        Returns:
        a new EncryptionProvider instance.
        Throws:
        CoreException - if the specified algorithm cannot be used or if the encryption secret key is not set as servlet context parameter or a System property.
        See Also:
        Options.OPTION_ENCRYPTION_SECRET_KEY
      • encrypt

        @Deprecated
        public abstract String encrypt​(String text)
                                throws CoreException
        Deprecated.
        This method relies on the default platform character encoding. Clients are advised to use the encrypt(String, String) method that allows specifying an explicit charset.
        Obfuscate the specified String content into a String that can hardly be interpreted by a human.
        Parameters:
        text - the text to encrypt.
        Returns:
        the encrypted text.
        Throws:
        CoreException - if the encryption algorithm cannot be used.
      • encrypt

        public abstract String encrypt​(String text,
                                       String charsetName)
                                throws CoreException
        Obfuscate the specified String content into a String that can hardly be interpreted by a human.
        Parameters:
        text - the text to encrypt.
        charsetName - the character encoding used to convert characters to bytes ("UTF-8" is recommended).
        Returns:
        the encrypted text.
        Throws:
        CoreException - if the encryption algorithm cannot be used.
        Since:
        2.1.3
      • decrypt

        @Deprecated
        public abstract String decrypt​(String text)
                                throws CoreException
        Deprecated.
        This method relies on the default platform character encoding. Clients are advised to use the decrypt(String, String) method that allows specifying an explicit charset.
        De-obfuscate the specified String into the original String that can be interpreted by a human.
        Parameters:
        text - the text to decrypt.
        Returns:
        the decrypted text.
        Throws:
        CoreException - if the encryption algorithm cannot be used.
        See Also:
        decrypt(String, String)
      • decrypt

        public abstract String decrypt​(String text,
                                       String charsetName)
                                throws CoreException
        De-obfuscate the specified String into the original String that can be interpreted by a human.
        Parameters:
        text - the text to decrypt.
        charsetName - the character encoding used to convert decrypted bytes to characters ("UTF-8" is recommended).
        Returns:
        the decrypted text.
        Throws:
        CoreException - if the encryption algorithm cannot be used or the charset is unknown.
        Since:
        2.1.3