Download Source

http://uploading.com/files/get/21f49292/Encription.rar

First you have to create a Rijndaelmanaged object.Then you can use that object for encryption. Then we should convert the string to a byte array using System.Text.Encoding.ASCII.GetBytes(string).

//create Rijendael object and generate keys
RM = new RijndaelManaged();
RM.GenerateKey();
RM.GenerateIV();

In encryption first we have to create a MemoryStream object and a CryptoStream object. From using these streams we write the byte array to the CryptoStream object. Then finally we get the MemoryStream object  as a array.

public byte[] EncriptData(byte[] data)
{
//variable to store encripted data
byte[] encrpted;

//using memory stream
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, RM.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(data, 0, data.Length);
cs.FlushFinalBlock();

}
encrpted = ms.ToArray();
}

return encrpted;

}

In decryption also we create MemoryStream and CryptoStream objects and read the decrypted byte[]  from the CryptoStream object.

public byte[] DecriptData(byte[] data)
{
byte[] decrpted=new byte[data.Length];

using (MemoryStream ms = new MemoryStream(data))
{
using (CryptoStream cs = new CryptoStream(ms, RM.CreateDecryptor(), CryptoStreamMode.Read))
{
cs.Read(decrpted, 0, data.Length);
}
}

return decrpted;
}