SymmetricAlgorithm.TryEncryptCbc 方法

定义

尝试使用具有指定填充模式的 CBC 模式将数据加密到指定的缓冲区中。

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

参数

plaintext
ReadOnlySpan<Byte>

要加密的数据。

iv
ReadOnlySpan<Byte>

初始化向量。

destination
Span<Byte>

用于接收密码文本数据的缓冲区。

bytesWritten
Int32

此方法返回时,包含写入到 destination的字节总数。

paddingMode
PaddingMode

用于在解密期间生成密码文本和删除的填充模式。

返回

true 如果 destination 大到足以接收加密数据,则为 ;否则为 false

例外

paddingMode 不是有效的填充模式。

iv 长度不正确。 调用方应传递长度正好 BlockSize 的初始化向量,该向量转换为字节 (BlockSize / 8) 。

无法成功加密纯文本。

注解

此方法的行为由 TryEncryptCbcCore(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)定义。

适用于