Class WorldPacketCrypt

java.lang.Object
br.net.dd.netherwingcore.common.cryptography.authentication.WorldPacketCrypt

public class WorldPacketCrypt extends Object
The WorldPacketCrypt class is responsible for encrypting and decrypting network packets with an implementation based on AES encryption. This class manages both packet decryption for incoming data and encryption for outgoing data. It also handles initialization vectors (IVs) and counters for the encryption and decryption processes to ensure data integrity and security.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Represents a cryptographic key used for initialization of the encryption and decryption algorithms.
    static class 
    Represents the Initialization Vector (IV) used in encryption and decryption processes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new WorldPacketCrypt instance with default AES configurations.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    decryptRecv(byte[] data, int length, AES.Tag tag)
    Decrypts the received data using the current client counter and verification tag.
    boolean
    encryptSend(byte[] data, int length, AES.Tag tag)
    Encrypts the given data using the current server counter and verification tag.
    void
    Initializes the cryptographic system with the given cryptographic key.
    boolean
    Checks whether the cryptographic system has been initialized.
    boolean
    peekDecryptRecv(byte[] data, int length)
    Performs a non-destructive decryption on the given data to verify its integrity, without modifying the input data's integrity.

    Methods inherited from class Object

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

    • WorldPacketCrypt

      public WorldPacketCrypt() throws Exception
      Constructs a new WorldPacketCrypt instance with default AES configurations.
      Throws:
      Exception - If the AES initialization fails.
  • Method Details

    • init

      public void init(WorldPacketCrypt.Key key)
      Initializes the cryptographic system with the given cryptographic key.
      Parameters:
      key - The cryptographic key used for both encryption and decryption.
    • peekDecryptRecv

      public boolean peekDecryptRecv(byte[] data, int length)
      Performs a non-destructive decryption on the given data to verify its integrity, without modifying the input data's integrity.
      Parameters:
      data - The data to be decrypted.
      length - The length of the data to be decrypted.
      Returns:
      true if the data can be successfully decrypted; false otherwise.
    • decryptRecv

      public boolean decryptRecv(byte[] data, int length, AES.Tag tag)
      Decrypts the received data using the current client counter and verification tag.
      Parameters:
      data - The data to be decrypted.
      length - The length of the data to be decrypted.
      tag - The cryptographic tag used for integrity verification.
      Returns:
      true if decryption is successful; false otherwise.
    • encryptSend

      public boolean encryptSend(byte[] data, int length, AES.Tag tag)
      Encrypts the given data using the current server counter and verification tag.
      Parameters:
      data - The data to be encrypted.
      length - The length of the data to be encrypted.
      tag - The cryptographic tag used for integrity verification.
      Returns:
      true if encryption is successful; false otherwise.
    • isInitialized

      public boolean isInitialized()
      Checks whether the cryptographic system has been initialized.
      Returns:
      true if the cryptographic system is initialized; false otherwise.