static void Demo1() { // SUMMARY: encrypt and decrypt string with explicit settings // create the plain text to be encrypted string PlainText = "The quick brown fox jumped over the lazy dog."; // create a password, iterations and salt size string Password = "******"; int Iterations = 11202; int SaltSize = 128; // empty salt to hold the value generated by encryption string SaltText; // encrypt the plain texd to cipher text, returning the generated salt string CipherText = Aes256EncryptionProvider.Encrypt(PlainText, out SaltText, Password, Iterations, SaltSize); // decrypt the cipher texdt back into plain text string PlainText2 = Aes256EncryptionProvider.Decrypt(CipherText, SaltText, Password, Iterations, SaltSize); Console.WriteLine("DEMO #1"); Console.WriteLine("======================="); Console.WriteLine("\nPlainText: {0}", PlainText); Console.WriteLine("\nIterations: {0}", Iterations.ToString("G")); Console.WriteLine("\nSaltSize: {0}", SaltSize.ToString("G")); Console.WriteLine("\nSalt: {0}", SaltText); Console.WriteLine("\nCipherText: {0}", CipherText); Console.WriteLine("\nPlainText2: {0}", PlainText2); Console.WriteLine(); }
static void Demo2() { // SUMMARY: encrypt and decrypt string with a static parameters // create the plain text to be encrypted string PlainText = "The quick brown fox jumped over the lazy dog."; // empty salt to hold the value generated by encryption string SaltText; // need to assign a static password provider implemntation Aes256EncryptionProvider.PasswordProvider = new AppSettingPasswordProvider(); // encrypt the plain texd to cipher text, returning the generated salt string CipherText = Aes256EncryptionProvider.Encrypt(PlainText, out SaltText); // decrypt the cipher texdt back into plain text string PlainText2 = Aes256EncryptionProvider.Decrypt(CipherText, SaltText); Console.WriteLine("DEMO #2"); Console.WriteLine("======================="); Console.WriteLine("\nPlainText: {0}", PlainText); Console.WriteLine("\nSalt: {0}", SaltText); Console.WriteLine("\nCipherText: {0}", CipherText); Console.WriteLine("\nPlainText2: {0}", PlainText2); Console.WriteLine(); }
public static string Decrypt(string CipherText, string SaltText) { // ValidateStaticInitialization();(); return(Aes256EncryptionProvider.Decrypt(CipherText, SaltText, Aes256EncryptionProvider.PasswordProvider.GetPassword(), Aes256EncryptionProvider.Iterations, Aes256EncryptionProvider.SaltSize)); }