Package art.cutils.security
Class AES<T>
- java.lang.Object
-
- art.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 class
AES.Algorithm
This holds validMessageDigest
algorithm types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
decrypt(@NotNull String itemToDecrypt)
This method will decrypt theitemToDecrypt
.String
encrypt(T itemToEncrypt)
This encrypt item of T type.boolean
equals(Object o)
int
hashCode()
static <T> @NotNull AES<T>
init()
This initiates encryption with defaultMessageDigest
AES.Algorithm.type
and encryption key.static <T> @NotNull AES<T>
init(AES.Algorithm algorithm)
This initiates encryption with the specifiedMessageDigest
AES.Algorithm.type
type and default Key.static <T> @NotNull AES<T>
init(AES.Algorithm algorithm, String encryptionKey)
This initiates encryption with the specifiedMessageDigest
AES.Algorithm.type
and encryption key.static <T> @NotNull AES<T>
init(String encryptionKey)
-
-
-
Method Detail
-
init
@Contract(" -> new") @NotNull public static <T> @NotNull AES<T> init() throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with defaultMessageDigest
AES.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
@Contract("_ -> new") @NotNull public static <T> @NotNull AES<T> init(String encryptionKey) throws NoSuchAlgorithmException, NoSuchPaddingException
- 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
@Contract("_ -> new") @NotNull public static <T> @NotNull AES<T> init(AES.Algorithm algorithm) throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with the specifiedMessageDigest
AES.Algorithm.type
type and default Key.- Type Parameters:
T
- Type of value- Parameters:
algorithm
- encryption algorithm ofAES.Algorithm
instance. 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:
- 1.0
-
init
@Contract("_, _ -> new") @NotNull public static <T> @NotNull AES<T> init(AES.Algorithm algorithm, String encryptionKey) throws NoSuchAlgorithmException, NoSuchPaddingException
This initiates encryption with the specifiedMessageDigest
AES.Algorithm.type
and encryption key.- Type Parameters:
T
- Type of value- Parameters:
encryptionKey
- user encryption Keyalgorithm
- encryption algorithm ofAES.Algorithm
instance. 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:
- 1.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
itemToEncrypt
of 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.
-
-