——此文章摘自《ASP
NET网络数据库开发实例精解》定价
¥
特价
¥
详细>>
public static void SetEncryptedCookie(String keyString valueString)
{ //设置使用DES加密后的Cookie
key = EncryptStringEncrypt(key);
valueString = EncryptStringEncrypt(valueString);
SetCookie(keyvalueString);
}
public static void SetEncryptedCookie(String key
String valueStringDateTime expires)
{ //设置使用DES加密后的Cookie并设置Cookie的有效时间
key = EncryptStringEncrypt(key);
valueString = EncryptStringEncrypt(valueString);
SetCookie(keyvalueStringexpires);
}
public static String GetTripleDESEncryptedCookieValue(String key)
{ //获取使用TripleDES解密后的Cookie
key = EncryptStringEncryptTripleDES(key);
String valueString = GetCookieValue(key);
valueString = EncryptStringDecryptTripleDES(valueString);
return(valueString);
}
public static String GetEncryptedCookieValue(String key)
{ //获取使用DES解密后的Cookie
key = EncryptStringEncrypt(key);
String valueString = GetCookieValue(key);
valueString = EncryptStringDecrypt(valueString);
return(valueString);
}
public static HttpCookie GetCookie(String key)
{ //通过关键字获取Cookie
key = HttpContextCurrentServerUrlEncode(key);
return(HttpContextCurrentRequestCookiesGet(key));
}
public static String GetCookieValue(String key)
{ //通过关键字获取Cookie的value
String valueString = GetCookie(key)Value;
valueString = HttpContextCurrentServerUrlDecode(valueString);
return(valueString);
}
}
.设计页面EncryptCookiesaspx
把应用程序Example__的默认页面WebFormaspx重命名为 EncryptCookiesaspx并在页面上添加个Label控件它们的名称分别为TripleDESCookie EncryptCookie和myCookie分别用来显示使用TripleDES加密后的Cookie的值使用DES加密后的Cookie的值和 Cookie的原始值页面EncryptCookiesaspx的设计界面如图所示
页面EncryptCookiesaspx的HTML设计代码如下
<asp:Label ID=myCookie Runat=server></asp:Label>
<asp:Label ID=EncryptCookie Runat=server></asp:Label>
<asp:Label ID=TripleDESCookie Runat=server></asp:Label>
[] [] [] [] []