本文整理汇总了C#中System.Security.Cryptography.AesManaged.Encrypt方法的典型用法代码示例。如果您正苦于以下问题:C# AesManaged.Encrypt方法的具体用法?C# AesManaged.Encrypt怎么用?C# AesManaged.Encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.AesManaged
的用法示例。
在下文中一共展示了AesManaged.Encrypt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encrypt
/// <summary>
/// Returns a binary array of encrypted data for the given parameters.
/// </summary>
/// <param name="source">Binary array of data to encrypt.</param>
/// <param name="startIndex">Offset into <paramref name="source"/> buffer.</param>
/// <param name="length">Number of bytes in <paramref name="source"/> buffer to encrypt starting from <paramref name="startIndex"/> offset.</param>
/// <param name="key">Encryption key to use to encrypt data.</param>
/// <param name="iv">Initialization vector to use to encrypt data.</param>
/// <param name="strength">Cryptographic strength to use when encrypting data.</param>
/// <returns>An encrypted version of the source data.</returns>
public static byte[] Encrypt(this byte[] source, int startIndex, int length, byte[] key, byte[] iv, CipherStrength strength)
{
if (strength == CipherStrength.None)
return source;
AesManaged symmetricAlgorithm = new AesManaged();
symmetricAlgorithm.KeySize = (int)strength;
return symmetricAlgorithm.Encrypt(source, startIndex, length, key, iv);
}