对HttpCookie)
Public Shared Sub SetCookie(ByVal cookie As HttpCookie)
HttpContext.Current.Response.Cookies.Set(cookie)
End Sub
''''获取COOKIE *****************************************************
Public Shared Function GetTripleDESEncryptedCookieValue(ByVal key As String) _
As String
''''只对密钥加密
key = CryptoUtil.EncryptTripleDES(key)
''''获取Cookie值
Dim value As String
value = GetCookieValue(key)
''''解密Cookie值
value = CryptoUtil.DecryptTripleDES(value)
Return value
End Function
Public Shared Function GetEncryptedCookieValue(ByVal key As String) As String
''''只对密钥加密
key = CryptoUtil.Encrypt(key)
''''获取Cookie值
Dim value As String
value = GetCookieValue(key)
''''解密Cookie值
value = CryptoUtil.Decrypt(value)
Return value
End Function
Public Shared Function GetCookie(ByVal key As String) As HttpCookie
''''编码密钥
key = HttpContext.Current.Server.UrlEncode(key)
Return HttpContext.Current.Request.Cookies.Get(key)
End Function
Public Shared Function GetCookieValue(ByVal key As String) As String
Try
''''编码在GetCookie里完成
''''获取Cookie值
Dim value As String
value = GetCookie(key).Value
''''解码所存储的值
value = HttpContext.Current.Server.UrlDecode(value)
Return value
Catch
End Try
End Function
End Class
上面的设置功能中,有些功能附加提供了Cookie有效期这个参数。不设置该参数,Cookie将只为浏览器会话才保存在内存中。为了设置永久的Cookie,就需要设置有效期参数。
上面我们对密钥和Cookies值进行了编码与解码,其原因是Cookies与URLs有同样的限制,字符“=”和“;”是保留的,不能使用。这在保存加密后的数据时尤其重要,因为加密算法将添加“=”,按所分配块的大小来填满该数据块。
好了,你会保护Cookies数据了吧?
上一页 [1] [2] [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]Henry手记-VB.NET中动态加载Treeview节点(二)
|