本文整理匯總了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);
}