Here is what you looking for my friend.
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
public sealed class Encryptor
{
#region " Private Static Members "
private static byte[] _savedKey = null;
private static byte[] _savedIV = null;
#endregion
#region " Private Static Methods "
private static void generateSecretKeyAndInitVector()
{
dynamic keyGen = new Rfc2898DeriveBytes("9be6ee5b-e76b-4d4d-86b9-20284fe6ba96", Encoding.ASCII.GetBytes("8726a597-eabe-4b0a-990f-29956dbb5e4a"));
_savedKey = keyGen.GetBytes(32);
_savedIV = keyGen.GetBytes(16);
}
#endregion
#region " Public Static Methods "
public static string Encrypt(string plainText)
{
byte[] plainTextAsBytes = Encoding.ASCII.GetBytes(plainText);
byte[] cipherTextAsBytes = {
};
using (MemoryStream memStream = new MemoryStream(plainTextAsBytes.Length))
{
using (RijndaelManaged rijndael = new RijndaelManaged())
{
generateSecretKeyAndInitVector();
if (_savedKey == null || _savedIV == null)
{
throw new NullReferenceException("savedKey and savedIV must be non-null.");
}
using (ICryptoTransform rdTransform = rijndael.CreateEncryptor((byte[])_savedKey.Clone(), (byte[])_savedIV.Clone()))
{
using (CryptoStream cryptoStream = new CryptoStream(memStream, rdTransform, CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextAsBytes, 0, plainTextAsBytes.Length);
cryptoStream.FlushFinalBlock();
cipherTextAsBytes = memStream.ToArray();
}
}
}
}
string cipherText = Convert.ToBase64String(cipherTextAsBytes);
return cipherText;
}
public static string Decrypt(string cipherText)
{
byte[] cipherTextAsBytes = Convert.FromBase64String(cipherText);
byte[] planeTextAsBytes = new Byte[cipherTextAsBytes.Length];
generateSecretKeyAndInitVector();
using (RijndaelManaged rijndael = new RijndaelManaged())
{
using (MemoryStream memStream = new MemoryStream(cipherTextAsBytes))
{
if (_savedKey == null || _savedIV == null)
{
throw new NullReferenceException("savedKey and savedIV must be non-null.");
}
using (ICryptoTransform rdTransform = rijndael.CreateDecryptor((byte[])_savedKey.Clone(), (byte[])_savedIV.Clone()))
{
using (CryptoStream cryptoStream = new CryptoStream(memStream, rdTransform, CryptoStreamMode.Read))
{
cryptoStream.Read(planeTextAsBytes, 0, planeTextAsBytes.Length);
}
}
}
}
string planeText = Encoding.ASCII.GetString(planeTextAsBytes);
return planeText;
}
#endregion
}
Good luck.