本文整理汇总了C#中System.Security.Cryptography.RC2CryptoServiceProvider.UseSalt属性的典型用法代码示例。如果您正苦于以下问题:C# RC2CryptoServiceProvider.UseSalt属性的具体用法?C# RC2CryptoServiceProvider.UseSalt怎么用?C# RC2CryptoServiceProvider.UseSalt使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Security.Cryptography.RC2CryptoServiceProvider
的用法示例。
在下文中一共展示了RC2CryptoServiceProvider.UseSalt属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace RC2CryptoServiceProvider_Examples
{
class MyMainClass
{
public static void Main()
{
byte[] originalBytes = ASCIIEncoding.ASCII.GetBytes("Here is some data.");
//Create a new RC2CryptoServiceProvider.
RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
rc2CSP.UseSalt = true;
rc2CSP.GenerateKey();
rc2CSP.GenerateIV();
//Encrypt the data.
MemoryStream msEncrypt = new MemoryStream();
CryptoStream csEncrypt = new CryptoStream(msEncrypt, rc2CSP.CreateEncryptor(rc2CSP.Key, rc2CSP.IV), CryptoStreamMode.Write);
//Write all data to the crypto stream and flush it.
csEncrypt.Write(originalBytes, 0, originalBytes.Length);
csEncrypt.FlushFinalBlock();
//Get encrypted array of bytes.
byte[] encryptedBytes = msEncrypt.ToArray();
//Decrypt the previously encrypted message.
MemoryStream msDecrypt = new MemoryStream(encryptedBytes);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, rc2CSP.CreateDecryptor(rc2CSP.Key, rc2CSP.IV), CryptoStreamMode.Read);
byte[] unencryptedBytes = new byte[originalBytes.Length];
//Read the data out of the crypto stream.
csDecrypt.Read(unencryptedBytes, 0, unencryptedBytes.Length);
//Convert the byte array back into a string.
string plaintext = ASCIIEncoding.ASCII.GetString(unencryptedBytes);
//Display the results.
Console.WriteLine("Unencrypted text: {0}", plaintext);
Console.ReadLine();
}
}
}