1

I have a simple post method in a MVC controller that checks whether the ModelState is valid then calls another method passing an instance of the model as a paramter. This model contains sensitive data that is easily obtained by looking at Fiddler. My goal is to somehow mask or encrypt this data so that it cannot be seen in an http trace.

I have seen posts suggesting to use Session or Temp variables but that is not an option in my case.

This is what the code looks like:

[HttpPost]
[ActionName("Search")]
[AccessControl(Xri)]
public ActionResult SearchPost(string string1, ViewModel model)
{
        model.NoResults = false;    

        if (ModelState.IsValid)
        {

           if (ModelState.IsValid) return RedirectToAction("TargetAction", model);            
         }

}

[AccessControl(Xri)]
public ActionResult TargetAction(string arg, ViewModel viewModel)
{
 .
 .
 .
}

Fiddler shows the following:

/TargetAction?id=01010101&date=08%2F14%2F2013%2000%3A00%3A00&To=08%2F21%2F2013%2000%3A00%3A00&param1=somevalue&param2=somevalue2

Is there a way to mask the url parameters shown here?

4

2 回答 2

1

您将需要在您的服务器上运行 SSL。

如果没有来自受信任机构的服务器证书,您几乎无法通过网络对数据进行加密。为什么?因为您需要在开始发送数据之前以明文形式发送加密/解密详细信息,以便您的客户端(可能是 JavaScript)可以对其进行解码。

使用证书并在 443 上运行可为您提供来自服务器/浏览器的内置功能,这在自定义实现中很难被击败。

如果您只想隐藏数据(并将其置于大多数 Web 用户之外),您始终可以对数据进行 base64 编码,而不是对其进行加密。请注意,您没有加密数据,并且仍然可以对其进行解码。这种方法不是一种加密形式。

如果您决定无论如何都采用这种方法,这里有一些资源: Client-side Encoding/Decoding MSDN Reference on Encoding to Base64

干杯。

于 2013-08-22T20:27:31.940 回答
0

您有两种选择:

  1. 将数据存储在服务器上,并给用户一个令牌(例如 GUID)以传递以检索数据。由于不能选择使用 Session 或 TempData,您可以将视图模型存储在数据库中,然后使用 URL 中的令牌重定向用户,以便在下一个请求时检索它。

  2. 另一种选择是让用户像您当前所做的那样在 URL 中传递视图模型,但以加密格式传递它。例如,您可以将模型序列化为 JSON,使用 .NET 的一种内置加密算法对其进行加密,然后重定向到将加密字符串作为视图模型传递的下一个操作。然后您可以将目标操作更改为:

    [访问控制(Xri)]
    公共 ActionResult TargetAction(字符串 arg,字符串 encryptedViewModel)
    {
      var decryptedString = Decrypt(encryptedViewModel) ; // 提供解密函数以匹配您的加密
      var viewModel = JsonConvert.DeserializeObject(decryptedString);
    }
于 2013-08-22T20:53:32.297 回答