ASP.net敏感信息存储 [英] ASP.net sensitive information storage

查看:198
本文介绍了ASP.net敏感信息存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的麻烦与ASP.net。我有一个小的数据表,我必须依赖于网页以及用户无法访问。我的意思是:


  

      
  1. 如果我存储从Hiddenfield里面的数据表中的数据,hiddenfield是页面相关的(多个同一页面不同的值
      请求),但它不是用户无法访问,因为用户可以修改其
      内容,然后回来后。


  2.   
  3. 如果我存储在会话数据表,即用户无法访问(这是好的),但由于一些内容从页面取决于
      这个值,如果用户打开的页面多次(在不同的
      标签),则会话与从最后一页的内容更新
      要求,因此老页面无法正常渲染,如果
      出现回发。


  4.   

例如:取一个整数变量。这是敏感信息。我需要这个值保存到,使用户无法修改它,它也可以为每个页面不同的值(同一个hiddenfield作品)。我怎样才能做到这一点?谢谢!

PS:我使用ASP.net 4.0与C#


解决方案

添加一个唯一的关键,隐藏字段;使用此键来访问一个唯一的会话值是特定于页面的实例。即使有人猜测别人的唯一密钥(S),这将是没有会话密钥没用。

例如:

 <输入类型=隐藏值=234092735029730ID =INSTANCEID=服务器/>

生成该值的第一次页面的实例呈现

 如果(!Page.IsPostback){
    。this.InstanceId.Value = GenerateKey()的ToString();
}

当检索从会话特定于该页面的值:

 字符串键= this.InstanceId.Value;
VAR值=会话[关键]

要生成一个网页,唯一的ID,这样的事情将工作:

 使用System.Security.Cryptography;私有静态RNGCryptoServiceProvider _crypto =新RNGCryptoServiceProvider();公共静态长GenerateKey(){
    字节[]字节=新的字节[8];
    _crypto.GetBytes(字节);
    返回BitConverter.ToInt64(字节,0);
}

请即该届会议并不一定100%的安全(如会话固定攻击 ),但它是几个数量级比存储在发送到客户端的数据中的信息的安全性。

I'm having a small trouble with ASP.net. I have a small DataTable that i need to be page dependent and also user inaccessible. What i mean is:

  1. If i store the data from the DataTable inside a Hiddenfield, the hiddenfield is page dependent (different values for multiple same page requests) but its not user inaccessible since a user can modify its content and then post back.

  2. If i store the Datatable in session, that is user inaccessible (which is good) but since some of the content from the page depends on this value, if a user opens the page multiple times (in different tabs) then the session is updated with the content from the last page requested and therefore the "older" pages are not properly rendered if a postback occurs.

Example: Take an integer variable. This is sensitive information. I need to save this value to so that users cannot modify it and it can also have different values for each page (same as a hiddenfield works). How can i do that? Thanks!

PS: i'm using ASP.net 4.0 with C#

解决方案

Add a unique key to a hidden field; use this key to access a unique session value that is specific to the instance of the page. Even if someone guessed someone else's unique key(s), it would be useless without the session key.

Example:

<input type="hidden" value="234092735029730" id="InstanceId" runat="server" />

Generate this value the first time the instance of the page is rendered:

if( !Page.IsPostback ){
    this.InstanceId.Value = GenerateKey().ToString();
}

When retrieving a value from Session specific to that page:

string key = this.InstanceId.Value;
var value = Session[key];

To generate a page-unique ID, something like this will work:

using System.Security.Cryptography;

private static RNGCryptoServiceProvider _crypto = new RNGCryptoServiceProvider();

public static long GenerateKey(){
    byte[] bytes = new byte[8];
    _crypto.GetBytes( bytes );
    return BitConverter.ToInt64( bytes, 0 );
}

Keep in mind that that Session isn't necessarily 100% secure (e.g. Session fixation attacks) but it is orders of magnitude more secure than storing the information in the data sent to the client.

这篇关于ASP.net敏感信息存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆