using System; using System.Security.Cryptography; using System.Text; public class Test { public static void Main() { string text = "Rvach.blogspot.com"; byte[] plainData, cipher, key, IV; SymmetricAlgorithm cryptoAlgoritm; ICryptoTransform cryptor; #region Encryptor plainData = Encoding.ASCII.GetBytes(text); // This static method creates a new cryptographic using the default // algorithm, which in .NET 4.5 is RijndaelManaged. cryptoAlgoritm = SymmetricAlgorithm.Create(); cryptor = cryptoAlgoritm.CreateEncryptor(cryptoAlgoritm.Key, cryptoAlgoritm.IV); cipher = cryptor.TransformFinalBlock(plainData, 0, plainData.Length); key = cryptoAlgoritm.Key; IV = cryptoAlgoritm.IV; cryptoAlgoritm.Clear(); Console.WriteLine("Cipher: "+ ASCIIEncoding.ASCII.GetString(cipher)); #endregion #region Decryptor cryptoAlgoritm = SymmetricAlgorithm.Create(); cryptor = cryptoAlgoritm.CreateDecryptor(key, IV); plainData = cryptor.TransformFinalBlock(cipher, 0, cipher.Length); cryptoAlgoritm.Clear(); Console.WriteLine("Plain: "+ ASCIIEncoding.ASCII.GetString(plainData)); #endregion Console.ReadKey(); } }