【问题标题】:How to encrypt Model values in RedirectToAction如何在 RedirectToAction 中加密模型值
【发布时间】:2017-04-04 19:50:24
【问题描述】:

如何加密和解密使用RedirectToAction 传递的模型值

public ActionResult CustomerDetails(CustomerModel model)
  {
        return RedirectToAction("ConfirmDetails", model);
  }

我想加密模型中的所有值并在ConfirmDetails方法中解密。

【问题讨论】:

标签: asp.net asp.net-mvc encryption


【解决方案1】:

我自己使用this 解密和加密方法,效果很好。你可以对输出做任何事情。

注意:阅读帖子并按他说的做。

运行加密:

使用起来很简单:只需实例化类,然后调用EncryptToString(string StringToEncrypt)DecryptString(string StringToDecrypt) 作为方法。一旦你有了这个类,它就再简单不过(或更安全)了。

在你的情况下是:

SimpleAES SEAS = new SimpleAES();
string decryptedstring = SEAS.EncryptToString(model.modelitem);

解密加密字符串:

SimpleAES SEAS = new SimpleAES();
string encryptedstring = SEAS.DecryptString(model.modelitem);

EDIT | 只是传递所有模型项:

List<string> EncryptedValues = new List<string>();
SimpleAES SEAS = new SimpleAES();
foreach(var modelitem in model)
{
     EncryptedValues.Add(SEAS.EncryptToString(Convert.ToString(modelitem)));
}

// Do something with the list.

【讨论】:

  • 这意味着,我必须加密和解密模型中的每个值。我一直在寻找一种方法来加密这样的模型对象Encrypt(model)
  • 我有 10 个字符串和日期的模型值。
  • @Angwenyi 查看已编辑的答案。注意:请务必将日期时间转换为字符串!你只需要有字符串!它无法转换 datetime 属性。
  • @Angwenyi,这不是你要找的方法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-07
  • 1970-01-01
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多