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:整个网站的性能
posted @ 2008-06-17 13:45  my favorite  阅读(981)  评论(0编辑  收藏  举报