using System.Security.Cryptography;
public class RijndaelSimple
public static string Encrypt
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
PasswordDeriveBytes password = new PasswordDeriveBytes
byte[] keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
string cipherText = Convert.ToBase64String(cipherTextBytes);
public static string Decrypt
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
PasswordDeriveBytes password = new PasswordDeriveBytes
byte[] keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform decryptor = symmetricKey.CreateDecryptor
MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
CryptoStream cryptoStream = new CryptoStream
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = cryptoStream.Read
string plainText = Encoding.UTF8.GetString
public class RijndaelSimpleTest
public static void Main(string[] args)
Console.Write("Enter any text:");
string plainText = Console.ReadLine();
string passPhrase = "G@K[<'h@(/=C=x27";
string saltValue = "vnn*625kR;;PuM&n+]p:()v6)s[R!K<%";
string hashAlgorithm = "SHA1";
int passwordIterations= 2;
string initVector = "@1B2c3D4e5F6g7H8";
Console.WriteLine(String.Format("text you have entered : {0} Length {1}", plainText, plainText.Length));
string cipherText = RijndaelSimple.Encrypt
Console.WriteLine(String.Format("text after encryption : {0} Length {1}", cipherText, cipherText.Length));
plainText = RijndaelSimple.Decrypt
Console.WriteLine(String.Format("original text after decryption : {0}", plainText));