Share via


ISpanAuthenticatedEncryptor.Encrypt<TWriter> Method

Definition

Encrypts and authenticates a piece of plaintext data and writes the result to a buffer writer.

public void Encrypt<TWriter>(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> additionalAuthenticatedData, ref TWriter destination) where TWriter : System.Buffers.IBufferWriter<byte>, allows ref struct;
abstract member Encrypt : ReadOnlySpan<byte> * ReadOnlySpan<byte> * 'Writer -> unit (requires 'Writer :> System.Buffers.IBufferWriter<byte>)
Public Sub Encrypt(Of TWriter As IBufferWriter(Of Byte)) (plaintext As ReadOnlySpan(Of Byte), additionalAuthenticatedData As ReadOnlySpan(Of Byte), ByRef destination As TWriter)

Type Parameters

TWriter

The type of buffer writer to write the ciphertext to.

Parameters

plaintext
ReadOnlySpan<Byte>

The plaintext to encrypt. This input may be zero bytes in length.

additionalAuthenticatedData
ReadOnlySpan<Byte>

A piece of data which will not be included in the returned ciphertext but which will still be covered by the authentication tag. This input may be zero bytes in length. The same AAD must be specified in the corresponding call to Decrypt<TWriter>(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, TWriter).

destination
TWriter

The buffer writer to which the ciphertext (including authentication tag) will be written.

Remarks

This method provides an optimized, streaming alternative to Encrypt(ArraySegment<Byte>, ArraySegment<Byte>). Rather than allocating an intermediate buffer, the ciphertext is written directly to the provided buffer writer, which can improve performance and reduce memory allocation pressure. The buffer writer is advanced by the total number of bytes written to it.

Applies to