AesGcm.Encrypt Method

Definition

Overloads

Encrypt(Byte[], Byte[], Byte[], Byte[], Byte[])

Encrypts the plaintext into the ciphertext destination buffer and generates the authentication tag into a separate buffer.

Encrypt(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, Span<Byte>, ReadOnlySpan<Byte>)

Encrypts the plaintext into the ciphertext destination buffer and generates the authentication tag into a separate buffer.

Encrypt(Byte[], Byte[], Byte[], Byte[], Byte[])

Source:
AesGcm.cs
Source:
AesGcm.cs
Source:
AesGcm.cs

Encrypts the plaintext into the ciphertext destination buffer and generates the authentication tag into a separate buffer.

C#
public void Encrypt(byte[] nonce, byte[] plaintext, byte[] ciphertext, byte[] tag, byte[]? associatedData = default);
C#
public void Encrypt(byte[] nonce, byte[] plaintext, byte[] ciphertext, byte[] tag, byte[] associatedData = default);

Parameters

nonce
Byte[]

The nonce associated with this message, which should be a unique value for every operation with the same key.

plaintext
Byte[]

The content to encrypt.

ciphertext
Byte[]

The byte array to receive the encrypted contents.

tag
Byte[]

The byte array to receive the generated authentication tag.

associatedData
Byte[]

Extra data associated with this message, which must also be provided during decryption.

Exceptions

The plaintext parameter and the ciphertext do not have the same length.

-or-

The nonce parameter length is not permitted by NonceByteSizes.

-or-

The tag parameter length is not permitted by TagByteSizes.

The nonce, ciphertext, tag, or plaintext parameter is null.

The encryption operation failed.

Remarks

The security guarantees of the AES-GCM algorithm mode require that the same nonce value is never used twice with the same key.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

Encrypt(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, Span<Byte>, ReadOnlySpan<Byte>)

Source:
AesGcm.cs
Source:
AesGcm.cs
Source:
AesGcm.cs

Encrypts the plaintext into the ciphertext destination buffer and generates the authentication tag into a separate buffer.

C#
public void Encrypt(ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> plaintext, Span<byte> ciphertext, Span<byte> tag, ReadOnlySpan<byte> associatedData = default);

Parameters

nonce
ReadOnlySpan<Byte>

The nonce associated with this message, which should be a unique value for every operation with the same key.

plaintext
ReadOnlySpan<Byte>

The content to encrypt.

ciphertext
Span<Byte>

The byte array to receive the encrypted contents.

tag
Span<Byte>

The byte array to receive the generated authentication tag.

associatedData
ReadOnlySpan<Byte>

Extra data associated with this message, which must also be provided during decryption.

Exceptions

The plaintext parameter and the ciphertext do not have the same length.

-or-

The nonce parameter length is not permitted by NonceByteSizes.

-or-

The tag parameter length is not permitted by TagByteSizes.

The encryption operation failed.

Remarks

The security guarantees of the AES-GCM algorithm mode require that the same nonce value is never used twice with the same key.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1