using System.Security.Cryptography;
public static void Main()
string data = Encrypt("dsfsdf", pw);
Console.WriteLine("Encrypted: " + data);
Console.WriteLine("Decrypted: " + Decrypt(data, pw));
private const string initVector = "h7g3e4m3t5st5zjw";
private const int keysize = 256;
public static string Encrypt(string plainText, string passPhrase)
byte[] initVectorBytes = Encoding.UTF8.GetBytes(initVector);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
Console.WriteLine("IV Byte Array: " + BitConverter.ToString(initVectorBytes).Replace("-", " ") + " (Size: " + initVectorBytes.Length.ToString() + ")");
var password = new PasswordDeriveBytes(passPhrase, null);
byte[] keyBytes = password.GetBytes(keysize / 8);
var symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
Console.WriteLine("Blocksize: " + symmetricKey.BlockSize.ToString() + "-Bit");
var encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes);
var memoryStream = new MemoryStream();
var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
return Convert.ToBase64String(cipherTextBytes);
public static string Decrypt(string cipherText, string passPhrase)
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
var password = new PasswordDeriveBytes(passPhrase, null);
byte[] keyBytes = password.GetBytes(keysize / 8);
var symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
var decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);
var memoryStream = new MemoryStream(cipherTextBytes);
var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
}V| shl Gvy} j! "e a; k i R‘ Vk 52 nj, Ni ‘ ey. y e sai.‘ «(0 Rhe gul! 4’ va»? I ‘g ”1%. . i|N ‘ . a. j .. n j 031‘ va. Nh ._ .9. 1: k“? s“... .u-DX; j va t .5 .k zb. ‘ g y~ . 7 ZR; gb ,2. ~ a3 N 7‘ g...» g.‘ . R» 5... .1! .z #7 .z. Yh C j. «R: 4 zz .a.¢ IV .9 W. ~y ,4:. 1‘: se. z ‘1 5a. a _ V l n Vs 5 "N 44 5‘. .2. cv: zl“, .8:.( u. 19.9j # n va z z qha : 4.. :1 g. p , .W n ~ , z _ .‘1 zy. N 0A4 .h h... :z. ’0 r... G. j ”JX .1, J4. yy 7 Y. . k. ._ 50‘ 14» U W -h 7%.} ah“? T. 4;. g; , c? P 1 zv Va hu. W. I: I” 3% a1 nk a . f h kk se. g. .ken‘. y; I... 21; z .Y.’ j «h v «z. z 1; I .4 Yh’n 'X‘WVHH. e’ v: ZX Z z Vs .a.‘ z __ J. Y} .. h nj. Yys.‘ «j k S i ”ng , z. .‘Ni‘y BVVL 4% i h. “v .9 .effyxj... U j havf? # % m.“ k. 1. «4 eW 9% .111 h . .n VHVVVY h j, y .4 G: “.1” j j .z j. z « J . 1.: ,z." 1&1 yAVa‘XW‘e 1‘f ‘56 .Q nf .54: e. 1:4? NJ «1, 1* #4,. iv 1...”. éjR , .4 p. a. -guG .J W _ n k n 1S: . ‘ 3 n 11 V~ 1‘ 11“. .1