Cookie加密

      Cookie中的数据以文本的形式存在客户端计算机,考虑它的安全性,最好在将数据存入Cookie之前对其进行加密。
加密的方法很多,比较简单一点的有:Base64,md5,sha等,而相对比较复杂一点的有:DES,TripleDES,RC2,Rijndael等。
下面是的代码实现了将数据存入Cookie之前采用散列的算法进行加密.
Private   void   Login_Click(object   sender,System   EventArgs   e)

      string   Name   =   NameBox.Text; 
      string   Pass   =   PassBox.Text; 
      Response.Cookies["name"].Value   =   FormsAuthentication.HashPasswordForStoringInConfigFile(Name,   "md5"); 
      Response.Cookies["pass"].Value   =   FormsAuthentication.HashPasswordForStoringInConfigFile(Pass,   "md5");

      加密的方法很多,使用比较复杂的加密算法,安全性比较高些,但占用服务器资源比较大,会减慢整个网站的访问速度。
所以对Cookie加密在考虑三个方面:1:安全性,2:Cookie容量,3:整个网站的性能。

      PS:哈希算法是不可逆的加密算法,因此可以用于密码的校对,如果需要可逆的加密算法,可选择DES、TripleDES等算法。

相关链接:
http://dudu.cnblogs.com/archive/2006/03/15/350441.html
http://www.cnblogs.com/sweetpig/articles/1305371.html

你可能感兴趣的:(cookie)