private void DecryptLogin(LoginViewModel model) { model.UserName = string.Empty; model.Password = string.Empty; var key = Request.Cookies["tokenBP1"].Value; var iv = Request.Cookies["tokenBP2"].Value; if (key != null && iv != null) { try { var crypto = new SimpleAes(); key = crypto.DecryptString(key); iv = crypto.DecryptString(iv); model.UserName = AesForLogin.DecryptStringAES(key, iv, model.Log1); model.Password = AesForLogin.DecryptStringAES(key, iv, model.Log2); } catch (Exception) { model.Password = string.Empty; ModelState.AddModelError("", "The user name or password provided is incorrect."); } } else { model.Password = string.Empty; ModelState.AddModelError("", "Your Session is expire please try login again"); } }
public void Should_encrypt_to_another_string_and_be_able_to_decrypt_to_original_string() { // Arrange var text = "!£$%^&*()_+汉字/漢字abcd"; // Act var result = _simpleAes.EncryptString(text); // Assert Assert.That(result, Is.Not.EqualTo(text)); Assert.That(_simpleAes.DecryptString(result), Is.EqualTo(text)); }
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); }