加密QueryString数据

2016-01-29 18:21 3 1 收藏

加密QueryString数据,加密QueryString数据

【 tulaoshi.com - ASP 】

  Problem with Query String Method  
Often time we use query string collection to retrieve an unique record from a table. Notice the following
piece of code -

Detail.asp?RecordID=200

Here we are passing a query string value called "RecordID" using the url. We then use the Query String collection "RecordID" to get the actual number -

<%
Dim RecordID
RecordID = Request.QueryString("RecordID")
%

The problem with the above method is that we are exposing "RecordID" to the public. Hence making easy to hackers to just change the RecordID Query string to retrieve other values of the table.

Solution to the above problem

In order to solve the above problem, we will use two ASP pages and the ASP random number function to scramble the passing query string value so that the real record number is not exposed to others.

On the first page we get a random number with the following code -

<%
Randomize timer
' Randomizing the timer function
rndNum = abs(int((rnd() * 3001)))
' To generate a prime based,  non-negative random number..
rndNum = rndNum + 53
Session("rndNum") = rndNum
'We place the random number value in a session variable so that we can use it again in the next page %

Now that we have our random number we will scramble our query string with it! Here is how -

<%
'Assuming you have a record set retrieved -
Display_Rs.movefirst
While not Display_Rs.Eof
Response.Write "<a href=detail.asp?RecordID="
Response.Write (Display_Rs("RecordID")*rndNum)
' Notice we are multiplying the actual record number with the random number to scramble the query 'string
Response.Write Display_Rs("RecordID") & "</a"
Display_Rs.Movenext
Wend
%

In the next page we will un-scramble the query string! Here is how -

<%
Dim RecordID
RecordID = request.querystring("RecordID")/Session("rndNum")
' We are dividing the record ID query string value with the same formula to un-scramble and pass the
actual record ID to the SQL statement
Session.abandon
' Releasing Session value for the next record
%

That's it! Using the above method you can scramble a query string as much as you like. For example multiply the random number with a very complex formula to generate an even more difficult integer number.
The key point here is you divide  the number with the same formula yielding to the original value. This technique is not full proof but much more difficult to break in that passing a regular query string value.


 

来源:http://www.tulaoshi.com/n/20160129/1505469.html

延伸阅读
地球人都知道,MDB文件很不安全,破解MDB文件密码的软件层出不穷,那是否如果我们MDB作后台数据库,是不是就等于任人宰割了呢?我觉得未必是这样的。 我用过不少Access密码破解器,大多数都只能处理英文密码,因此我们可以针对这一特点,把MDB文件的数据库密码设置为中文的,这样就可以抵挡大部份破解器的攻击了。 一定有人会说,既然人家...
加密它:用新的高级加密标准(AES)保持你的数据安全 原著:James McCaffrey 翻译:小刀人 原文出处:MSDN Magazine November 2003 (Encrypt It) 本文的代码下载:msdnmag200311AES.exe (143KB) 本文假设你熟悉 C# 和 位(bit)操作。 ...
问题 安全是任何公司的一个主要考量。数据库备份容易被偷并被恢复到另一个SQL Server实例上。当我们浏览SQL Server 2008的新特性时,我们对一个叫做透明数据加密的特性很感兴趣,我们可以用它来加密我们的数据库备份。你能为我们详细介绍下应该怎样使用这个新功能吗? 专家解答 透明数据加密是SQL Server 2008的一个新特性...
标签: ASP
  当用户填写页面<FORM>内容时所提供的全部值,或在浏览器地址栏输入在URL后的值,通过Form和QueryString集合为ASP脚本所用。这是在ASP代码中访问值的一种简单方法。 1、 访问ASP集合的一般技术 大多数ASP集合与在VB中见到的普通集合相差不多。实际上,它们是值的数组,但能通过使用一个文本字符串键(对大小不敏感)以...
标签: Web开发
当使用表单的Get 方式提交数据时,表单中的数据被保存在 Request 对象的 Querystring 集合中。除了读取表单对象传递的参数外,Querystring 集合还可以通过读取 HTTP 查询字符串中的参数值来传递参数。使用 Querystring 集合来传递数据的语法格式如下: Request.Querstring (变量名) [(索引值)|.变量的个数] 注解: 变量为在 HTTP 查...

经验教程

478

收藏

49

精华推荐

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部