Class AES
java.lang.Object
br.net.dd.netherwingcore.common.cryptography.AES
Utility class for AES (Advanced Encryption Standard) based cryptography operations.
This class supports both encryption and decryption of data using AES GCM (Galois/Counter Mode).
It provides functionality for key, IV (Initialization Vector), and tag management.
Features: - Supports AES-128 encryption mode. - Provides wrappers for key, IV, and tag with automatic validation. - Handles encryption and decryption integrity checks. - Includes optional processing without integrity verification (uses AES/CTR mode).
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinit(byte[] key) Initializes the AES instance with the specified key.voidInitializes the AES instance with the specifiedAES.Key.booleanProcesses encryption or decryption for AES using the specified IV and Tag.booleanprocessNoIntegrityCheck(AES.IV iv, byte[] data, int partialLength) Processes decryption without integrity checks using AES CTR (Counter Mode).
-
Field Details
-
IV_SIZE_BYTES
public static final int IV_SIZE_BYTES- See Also:
-
KEY_SIZE_BYTES
public static final int KEY_SIZE_BYTES- See Also:
-
TAG_SIZE_BYTES
public static final int TAG_SIZE_BYTES- See Also:
-
-
Constructor Details
-
AES
public AES(boolean encrypting, int keySizeBits) Constructs an AES instance for encryption or decryption.- Parameters:
encrypting- true if this instance is for encryption, false for decryption.keySizeBits- the size of the AES key in bits (must be 128, 192, or 256).
-
AES
public AES(boolean encrypting) Constructs an AES instance for encryption or decryption with a default key size of 128 bits.- Parameters:
encrypting- true if this instance is for encryption, false for decryption.
-
-
Method Details
-
init
public void init(byte[] key) Initializes the AES instance with the specified key.- Parameters:
key- the AES key as a byte array.- Throws:
IllegalArgumentException- if the key length is notKEY_SIZE_BYTES.
-
init
-
process
Processes encryption or decryption for AES using the specified IV and Tag.- Parameters:
iv- the initialization vector used for AES GCM mode.data- the input data for encryption or decryption.length- the length of the data to process.tag- the output tag (for encryption) or input tag (for decryption).- Returns:
- true if the operation succeeds, false otherwise.
-
processNoIntegrityCheck
Processes decryption without integrity checks using AES CTR (Counter Mode).Note: This mode does not provide data authenticity or integrity validation.
- Parameters:
iv- the initialization vector for AES CTR mode.data- the input ciphertext for decryption.partialLength- the length of the input data.- Returns:
- true if the operation is successful, false otherwise.
-