public ActionResult Login(string ReturnUrl = "") { ViewBag.ReturnUrl = ReturnUrl; var crypto = new SimpleAes(); Session["BPKey"] = AesForLogin.Create16DigitString(); Session["BPKeyIV"] = AesForLogin.Create16DigitString(); var cookie1 = new HttpCookie("tokenBP1"); var cookie2 = new HttpCookie("tokenBP2"); cookie1.Value = crypto.EncryptToString(Session["BPKey"].ToString()); cookie2.Value = crypto.EncryptToString(Session["BPKeyIV"].ToString()); Response.Cookies.Remove("tokenBP1"); Response.Cookies.Remove("tokenBP2"); Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); return(View()); }
private static void DemoEncrypt() { var generateEncryptionKey = SimpleAes.GenerateEncryptionKey(); foreach (var b in generateEncryptionKey) { Console.Write(b); Console.Write(","); } Console.WriteLine(); var generateEncryptionVector = SimpleAes.GenerateEncryptionVector(); foreach (var b in generateEncryptionVector) { Console.Write(b); Console.Write(","); } Console.WriteLine(); Console.WriteLine("------SimpleAes-----"); var simpleAes = new SimpleAes(); var @join = string.Join(",", Enumerable.Repeat("b2f28db601599e3c1271117acfd9caed1d4abfb3", 1000).ToArray()); //var @join = simpleAes.EncryptToString("b2f28db601599e3c1271117acfd9caed1d4abfb3"); var encrypt = simpleAes.EncryptToString(@join); Console.WriteLine(encrypt.Length); var decryptString = simpleAes.DecryptString(encrypt); Console.WriteLine(decryptString.Length); Console.WriteLine("----StringCompressor----"); var stringCompressor = StringCompressor.Instance; var compressString = stringCompressor.CompressString(encrypt); Console.WriteLine(compressString.Length); var decompressString = stringCompressor.DecompressString(compressString); Console.WriteLine(decompressString.Length); Console.WriteLine("----ZipHelper----"); var bytes = ZipHelper.Zip(encrypt); Console.WriteLine(bytes.Length); var unzip = ZipHelper.Unzip(bytes); Console.WriteLine(unzip.Length); }