Class ChaCha20Poly1305
- Namespace
- NLightning.Common.Crypto.Ciphers
- Assembly
- NLightning.Common.dll
AEAD_CHACHA20_POLY1305 from RFC 7539. The 96-bit nonce is formed by encoding 32 bits of zeros followed by little-endian encoding of n.
public sealed class ChaCha20Poly1305
- Inheritance
-
ChaCha20Poly1305
- Inherited Members
Methods
Decrypt(ReadOnlySpan<byte>, ulong, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)
Decrypts ciphertext using a cipher key of 32 bytes, an 8-byte unsigned integer publicNonce, and authenticationData. Reads the result into plaintext parameter and returns the number of bytes read, unless authentication fails, in which case an error is signaled to the caller.
public int Decrypt(ReadOnlySpan<byte> key, ulong publicNonce, ReadOnlySpan<byte> authenticationData, ReadOnlySpan<byte> ciphertext, Span<byte> plaintext)
Parameters
key
ReadOnlySpan<byte>publicNonce
ulongauthenticationData
ReadOnlySpan<byte>ciphertext
ReadOnlySpan<byte>plaintext
Span<byte>
Returns
Encrypt(ReadOnlySpan<byte>, ulong, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)
Encrypts plaintext using the cipher key of 32 bytes and an 8-byte unsigned integer publicNonce which must be unique for the key. Writes the result into ciphertext parameter and returns the number of bytes written. Encryption must be done with an "AEAD" encryption mode with the authenticationData and results in a ciphertext that is the same size as the plaintext plus 16 bytes for authentication data.
public int Encrypt(ReadOnlySpan<byte> key, ulong publicNonce, ReadOnlySpan<byte> authenticationData, ReadOnlySpan<byte> plaintext, Span<byte> ciphertext)
Parameters
key
ReadOnlySpan<byte>publicNonce
ulongauthenticationData
ReadOnlySpan<byte>plaintext
ReadOnlySpan<byte>ciphertext
Span<byte>