Class AES

java.lang.Object
br.net.dd.netherwingcore.common.cryptography.AES

public class AES extends Object
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
    Modifier and Type
    Class
    Description
    static final record 
    Represents an AES Initialization Vector (IV).
    static final record 
    Represents an AES key encapsulating its byte data and validation logic.
    static final record 
    Represents an AES authentication tag.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    AES(boolean encrypting)
    Constructs an AES instance for encryption or decryption with a default key size of 128 bits.
    AES(boolean encrypting, int keySizeBits)
    Constructs an AES instance for encryption or decryption.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    init(byte[] key)
    Initializes the AES instance with the specified key.
    void
    Initializes the AES instance with the specified AES.Key.
    boolean
    process(AES.IV iv, byte[] data, int length, AES.Tag tag)
    Processes encryption or decryption for AES using the specified IV and Tag.
    boolean
    processNoIntegrityCheck(AES.IV iv, byte[] data, int partialLength)
    Processes decryption without integrity checks using AES CTR (Counter Mode).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 not KEY_SIZE_BYTES.
    • init

      public void init(AES.Key key)
      Initializes the AES instance with the specified AES.Key.
      Parameters:
      key - the AES key encapsulated in a AES.Key object.
    • process

      public boolean process(AES.IV iv, byte[] data, int length, AES.Tag tag)
      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

      public boolean processNoIntegrityCheck(AES.IV iv, byte[] data, int partialLength)
      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.