static void Main(string[] args)
{
SymmetricAlgorithm provider = SymmetricAlgorithm.Create("TripleDES");
provider.Key = Encoding.Default.GetBytes("6HD+Ngi8JoGmDog=");
provider.IV = Encoding.Default.GetBytes("gi8joCmd");
ICryptoTransform encryptor = provider.CreateEncryptor();
string clearData = "This is test";
Console.WriteLine("Clear Data:" + clearData);
Stream clearData1 = new MemoryStream(Encoding.Default.GetBytes(clearData));
Stream encryptedData = new MemoryStream();
CryptoStream crypoStream = new CryptoStream(encryptedData, encryptor, CryptoStreamMode.Write);
byte[] buffer = new byte[1024];
int count = 0;
while ((count = clearData1.Read(buffer, 0, 1024)) > 0)
{
crypoStream.Write(buffer, 0, count);
}
crypoStream.FlushFinalBlock();
encryptedData.Position = 0;
byte[] encryptedDataArray = new Byte[encryptedData.Length];
encryptedData.Read(encryptedDataArray, 0, encryptedDataArray.Length);
Console.WriteLine("Encrypted data:"+Encoding.Default.GetString(encryptedDataArray ));
Console.ReadLine();
}
{
SymmetricAlgorithm provider = SymmetricAlgorithm.Create("TripleDES");
provider.Key = Encoding.Default.GetBytes("6HD+Ngi8JoGmDog=");
provider.IV = Encoding.Default.GetBytes("gi8joCmd");
ICryptoTransform encryptor = provider.CreateEncryptor();
string clearData = "This is test";
Console.WriteLine("Clear Data:" + clearData);
Stream clearData1 = new MemoryStream(Encoding.Default.GetBytes(clearData));
Stream encryptedData = new MemoryStream();
CryptoStream crypoStream = new CryptoStream(encryptedData, encryptor, CryptoStreamMode.Write);
byte[] buffer = new byte[1024];
int count = 0;
while ((count = clearData1.Read(buffer, 0, 1024)) > 0)
{
crypoStream.Write(buffer, 0, count);
}
crypoStream.FlushFinalBlock();
encryptedData.Position = 0;
byte[] encryptedDataArray = new Byte[encryptedData.Length];
encryptedData.Read(encryptedDataArray, 0, encryptedDataArray.Length);
Console.WriteLine("Encrypted data:"+Encoding.Default.GetString(encryptedDataArray ));
Console.ReadLine();
}