Package alpine.crypto
Class DataEncryption
- java.lang.Object
-
- alpine.crypto.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decryptAsBytes(byte[] encryptedIvTextBytes)Decrypts the specified bytes using AES-256.static byte[]decryptAsBytes(SecretKey secretKey, byte[] encryptedIvTextBytes)Decrypts the specified bytes using AES-256.static StringdecryptAsString(String encryptedText)Decrypts the specified string using AES-256.static StringdecryptAsString(SecretKey secretKey, String encryptedText)Decrypts the specified string using AES-256.static byte[]encryptAsBytes(String plainText)Encrypts the specified plainText using AES-256.static byte[]encryptAsBytes(SecretKey secretKey, String plainText)Encrypts the specified plainText using AES-256.static StringencryptAsString(String plainText)Encrypts the specified plainText using AES-256 and returns a Base64 encoded representation of the encrypted bytes.static StringencryptAsString(SecretKey secretKey, String plainText)Encrypts the specified plainText using AES-256 and returns a Base64 encoded representation of the encrypted bytes.
-
-
-
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 encryptsecretKey- 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 withplainText- 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 withencryptedIvTextBytes- 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 ExceptionDecrypts 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 fromencryptAsString(String).- Parameters:
secretKey- the secret key to decrypt withencryptedText- 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 fromencryptAsString(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
-
-