SymmetricAlgorithm.DecryptCbc Method

Definition

Overloads

DecryptCbc(Byte[], Byte[], PaddingMode)

Decrypts data using CBC mode with the specified padding mode.

DecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, PaddingMode)

Decrypts data using CBC mode with the specified padding mode.

DecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode)

Decrypts data into the specified buffer, using CBC mode with the specified padding mode.

DecryptCbc(Byte[], Byte[], PaddingMode)

Source:
SymmetricAlgorithm.cs
Source:
SymmetricAlgorithm.cs
Source:
SymmetricAlgorithm.cs

Decrypts data using CBC mode with the specified padding mode.

C#
public byte[] DecryptCbc (byte[] ciphertext, byte[] iv, System.Security.Cryptography.PaddingMode paddingMode = System.Security.Cryptography.PaddingMode.PKCS7);

Parameters

ciphertext
Byte[]

The data to decrypt.

iv
Byte[]

The initialization vector.

paddingMode
PaddingMode

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

Returns

Byte[]

The decrypted plaintext data.

Exceptions

ciphertext or iv is null.

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 ciphertext could not be decrypted successfully.

Remarks

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

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9

DecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, PaddingMode)

Source:
SymmetricAlgorithm.cs
Source:
SymmetricAlgorithm.cs
Source:
SymmetricAlgorithm.cs

Decrypts data using CBC mode with the specified padding mode.

C#
public byte[] DecryptCbc (ReadOnlySpan<byte> ciphertext, ReadOnlySpan<byte> iv, System.Security.Cryptography.PaddingMode paddingMode = System.Security.Cryptography.PaddingMode.PKCS7);

Parameters

ciphertext
ReadOnlySpan<Byte>

The data to decrypt.

iv
ReadOnlySpan<Byte>

The initialization vector.

paddingMode
PaddingMode

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

Returns

Byte[]

The decrypted plaintext data.

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 ciphertext could not be decrypted successfully.

Remarks

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

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9

DecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode)

Source:
SymmetricAlgorithm.cs
Source:
SymmetricAlgorithm.cs
Source:
SymmetricAlgorithm.cs

Decrypts data into the specified buffer, using CBC mode with the specified padding mode.

C#
public int DecryptCbc (ReadOnlySpan<byte> ciphertext, ReadOnlySpan<byte> iv, Span<byte> destination, System.Security.Cryptography.PaddingMode paddingMode = System.Security.Cryptography.PaddingMode.PKCS7);

Parameters

ciphertext
ReadOnlySpan<Byte>

The data to decrypt.

iv
ReadOnlySpan<Byte>

The initialization vector.

destination
Span<Byte>

The buffer to receive the plaintext data.

paddingMode
PaddingMode

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

Returns

The total number of bytes written to destination

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 ciphertext could not be decrypted successfully.

The buffer in destination is too small to hold the plaintext data.

Remarks

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

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9