Bewerken

Share via


SymmetricAlgorithm.TryEncryptCbc Method

Definition

Attempts to encrypt data into the specified buffer, using CBC mode with the specified padding mode.

public bool TryEncryptCbc (ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> iv, Span<byte> destination, out int bytesWritten, System.Security.Cryptography.PaddingMode paddingMode = System.Security.Cryptography.PaddingMode.PKCS7);
member this.TryEncryptCbc : ReadOnlySpan<byte> * ReadOnlySpan<byte> * Span<byte> * int * System.Security.Cryptography.PaddingMode -> bool
Public Function TryEncryptCbc (plaintext As ReadOnlySpan(Of Byte), iv As ReadOnlySpan(Of Byte), destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional paddingMode As PaddingMode = System.Security.Cryptography.PaddingMode.PKCS7) As Boolean

Parameters

plaintext
ReadOnlySpan<Byte>

The data to encrypt.

iv
ReadOnlySpan<Byte>

The initialization vector.

destination
Span<Byte>

The buffer to receive the ciphertext data.

bytesWritten
Int32

When this method returns, contains the total number of bytes written to destination.

paddingMode
PaddingMode

The padding mode used to produce the ciphertext and remove during decryption.

Returns

true if destination was large enough to receive the encrypted data; otherwise, false.

Exceptions

paddingMode is not a valid padding mode.

iv is the incorrect length. Callers are expected to pass an initialization vector that is exactly BlockSize in length, converted to bytes (BlockSize / 8).

The plaintext could not be encrypted successfully.

Remarks

This method's behavior is defined by TryEncryptCbcCore(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32).

Applies to