Package pro.horde.os.cutils.security
Class AES<T>
- java.lang.Object
-
- pro.horde.os.cutils.security.AES<T>
-
- Type Parameters:
T- Type of value
- All Implemented Interfaces:
Serializable
public final class AES<T> extends Object implements Serializable
This is an implementation of Advanced Encryption Standard, to can encrypt and decrypt Objects of any type.- Since:
- 1.0
- Author:
- Bobai Kato
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAES.AlgorithmThis holds validMessageDigestalgorithm types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tdecrypt(@NotNull String itemToDecrypt)This method will decrypt theitemToDecrypt.Stringencrypt(T itemToEncrypt)This encrypt item of T type.booleanequals(Object o)inthashCode()static <T> AES<T>init()This initiates encryption with default algorithm type and encryption key.static <T> AES<T>init(String encryptionKey)This initiates encryption with the default:SHA-256.static <T> AES<T>init(AES.Algorithm algorithm)This initiates encryption with the specified algorithm type.static <T> AES<T>init(AES.Algorithm algorithm, String encryptionKey)This initiates encryption with the specified algorithm type and encryption key.
-
-
-
Method Detail
-
init
public static <T> AES<T> init() throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with default algorithm type and encryption key.- Type Parameters:
T- Type of value- Returns:
- Instance of
AES - Throws:
NoSuchAlgorithmException- This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.NoSuchPaddingException- This exception is thrown when a particular padding mechanism is requested but is not available in the environment.- Since:
- 1.0
-
init
public static <T> AES<T> init(String encryptionKey) throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with the default:SHA-256.- Type Parameters:
T- Type of value- Parameters:
encryptionKey- user encryption Key- Returns:
- Instance of
AES - Throws:
NoSuchAlgorithmException- This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.NoSuchPaddingException- This exception is thrown when a particular padding mechanism is requested but is not available in the environment.- Since:
- 1.0
-
init
public static <T> AES<T> init(AES.Algorithm algorithm, String encryptionKey) throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with the specified algorithm type and encryption key.- Type Parameters:
T- Type of value- Parameters:
encryptionKey- user encryption Keyalgorithm- encryption algorithm ofAES.Algorithminstance. SHA256 is set ifnull.- Returns:
- Instance of
AES - Throws:
NoSuchAlgorithmException- This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.NoSuchPaddingException- This exception is thrown when a particular padding mechanism is requested but is not available in the environment.- Since:
- 5.0
-
init
public static <T> AES<T> init(AES.Algorithm algorithm) throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with the specified algorithm type.- Type Parameters:
T- Type of value- Parameters:
algorithm- encryption algorithm ofAES.Algorithminstance. SHA256 is set ifnull.- Returns:
- Instance of
AES - Throws:
NoSuchAlgorithmException- This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.NoSuchPaddingException- This exception is thrown when a particular padding mechanism is requested but is not available in the environment.- Since:
- 5.0
-
encrypt
public String encrypt(@Valid T itemToEncrypt) throws InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException
This encrypt item of T type.- Parameters:
itemToEncrypt- item to encrypt.- Returns:
- encrypted string of
itemToEncryptof T type. Not null - Throws:
InvalidAlgorithmParameterException- This is the exception for invalid or inappropriate algorithm parameters.InvalidKeyException- This is the exception for invalid Keys (invalid encoding, wrong * length, uninitialized, etc).BadPaddingException- This exception is thrown when a particular padding mechanism is expected for the input data but the data is not padded properly.IllegalBlockSizeException- This exception is thrown when the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher.IOException- Signals that an I/O exception of some sort has occurred.
-
decrypt
public T decrypt(@NotNull @NotNull String itemToDecrypt) throws InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException
This method will decrypt theitemToDecrypt.- Parameters:
itemToDecrypt- encrypted string to be decrypted. not null- Returns:
- decrypted Object.
- Throws:
InvalidAlgorithmParameterException- exception for invalid or inappropriate algorithm parameters.InvalidKeyException- exception for invalid KeysBadPaddingException- This exception is thrown when a particular padding mechanism is * expected for the input data but the data is not padded properly.IllegalBlockSizeException- This exception is thrown when the length of data provided to a block * cipher is incorrect, i.e., does not match the block size of the cipher.
-
-