ChaCha20Poly1305Managed
Implements ChaCha20-Poly1305 authenticated encryption with associated data (AEAD), as specified in RFC 8439.
Nebula · Packages/com.1by3.nebula/Runtime/Transport/NebulaCrypto.cspublic static class ChaCha20Poly1305ManagedImplements ChaCha20-Poly1305 authenticated encryption with associated data (AEAD), as specified in RFC 8439. It uses a 32-byte key, a 12-byte nonce, and a 16-byte authentication tag. Ciphertext has the same length as plaintext; the tag adds 16 bytes. A nonce must not be reused with the same key.
Fields
KeySize
public const int KeySize = 32;NonceSize
public const int NonceSize = 12;TagSize
public const int TagSize = 16;Methods
Seal
public static int Seal(byte[] key, byte[] nonce, ArraySegment<byte> plaintext, byte[] aad, int aadLength, byte[] output, int outputOffset);Encrypt plaintext into output (ciphertext then the 16-byte tag). output needs plaintext.Count + 16 bytes from outputOffset.
SealManaged
public static int SealManaged(byte[] key, byte[] nonce, ArraySegment<byte> plaintext, byte[] aad, int aadLength, byte[] output, int outputOffset);Encrypts the payload and appends its 16-byte authentication tag using the managed implementation used by Unity builds.
Open
public static int Open(byte[] key, byte[] nonce, ArraySegment<byte> sealedInput, byte[] aad, int aadLength, byte[] output, int outputOffset);Verifies the authentication tag and decrypts into output. Returns the plaintext length, or -1 if the input is shorter than a tag or authentication fails. Output is valid only on success.
OpenManaged
public static int OpenManaged(byte[] key, byte[] nonce, ArraySegment<byte> sealedInput, byte[] aad, int aadLength, byte[] output, int outputOffset);Verifies and decrypts with the managed implementation. Returns the plaintext length, or -1 for a truncated tag or failed authentication.