Package alpine.crypto

Class DataEncryption


  • public class DataEncryption
    extends Object
    This class performs symmetric encryption of data using the system-defined secret key. The encryption routines in this class require the use of the unlimited strength policy files, included in the most recent versions of Java by default. Older Java versions may need to install the policy files for the methods in this class to function correctly.
    Since:
    1.3.0
    Author:
    Steve Springett
    • Method Detail

      • encryptAsBytes

        public static byte[] encryptAsBytes​(SecretKey secretKey,
                                            String plainText)
                                     throws Exception
        Encrypts the specified plainText using AES-256.
        Parameters:
        plainText - the text to encrypt
        secretKey - the secret key to use to encrypt with
        Returns:
        the encrypted bytes
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • encryptAsBytes

        public static byte[] encryptAsBytes​(String plainText)
                                     throws Exception
        Encrypts the specified plainText using AES-256. This method uses the default secret key.
        Parameters:
        plainText - the text to encrypt
        Returns:
        the encrypted bytes
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • encryptAsString

        public static String encryptAsString​(SecretKey secretKey,
                                             String plainText)
                                      throws Exception
        Encrypts the specified plainText using AES-256 and returns a Base64 encoded representation of the encrypted bytes.
        Parameters:
        secretKey - the secret key to use to encrypt with
        plainText - the text to encrypt
        Returns:
        a Base64 encoded representation of the encrypted bytes
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • encryptAsString

        public static String encryptAsString​(String plainText)
                                      throws Exception
        Encrypts the specified plainText using AES-256 and returns a Base64 encoded representation of the encrypted bytes. This method uses the default secret key.
        Parameters:
        plainText - the text to encrypt
        Returns:
        a Base64 encoded representation of the encrypted bytes
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • decryptAsBytes

        public static byte[] decryptAsBytes​(SecretKey secretKey,
                                            byte[] encryptedIvTextBytes)
                                     throws Exception
        Decrypts the specified bytes using AES-256.
        Parameters:
        secretKey - the secret key to decrypt with
        encryptedIvTextBytes - the text to decrypt
        Returns:
        the decrypted bytes
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • decryptAsBytes

        public static byte[] decryptAsBytes​(byte[] encryptedIvTextBytes)
                                     throws Exception
        Decrypts the specified bytes using AES-256. This method uses the default secret key.
        Parameters:
        encryptedIvTextBytes - the text to decrypt
        Returns:
        the decrypted bytes
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • decryptAsString

        public static String decryptAsString​(SecretKey secretKey,
                                             String encryptedText)
                                      throws Exception
        Decrypts the specified string using AES-256. The encryptedText is expected to be the Base64 encoded representation of the encrypted bytes generated from encryptAsString(String).
        Parameters:
        secretKey - the secret key to decrypt with
        encryptedText - the text to decrypt
        Returns:
        the decrypted string
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0
      • decryptAsString

        public static String decryptAsString​(String encryptedText)
                                      throws Exception
        Decrypts the specified string using AES-256. The encryptedText is expected to be the Base64 encoded representation of the encrypted bytes generated from encryptAsString(String). This method uses the default secret key.
        Parameters:
        encryptedText - the text to decrypt
        Returns:
        the decrypted string
        Throws:
        Exception - a number of exceptions may be thrown
        Since:
        1.3.0