asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

使用ASP.Net加密Cookie[3]


发布日期:2019年06月21日
 
使用ASP.Net加密Cookie[3]
——此文章摘自《ASPNET网络数据库开发实例精解》定价 特价 详细>>

CryptoStream cryptoStream = new CryptoStream(memoryStream

triproviderCreateEncryptor(KeyIV)

CryptoStreamModeRead);

//定义读IO流

StreamReader readerStream = new StreamReader(cryptoStream);

//返回解密后的字符串

return(readerStreamReadToEnd());

}

return(null);

}

}

.创建处理Cookie的类CookieEncrypt

在应用程序Example__中的类文件EncryptStringcs中添加类CookieEncrypt该类用来处理应用程序的Cookie如加密Cookie获取Cookie解密Cookie等类CookieEncrypt的程序代码如下

public class CookieEncrypt

{

public static void SetCookie(HttpCookie cookie)

{ //设置Cookie

HttpContextCurrentResponseCookiesSet(cookie);

}

public static void SetCookie(String keyString valueString)

{ //设置加密后的Cookie

key = HttpContextCurrentServerUrlEncode(key);

valueString = HttpContextCurrentServerUrlEncode(valueString);

HttpCookie cookie = new HttpCookie(keyvalueString);

SetCookie(cookie);

}

public static void SetCookie(String keyString valueString

DateTime expires)

{ //设置加密后的Cookie并设置Cookie的有效时间

key = HttpContextCurrentServerUrlEncode(key);

valueString = HttpContextCurrentServerUrlEncode(valueString);

HttpCookie cookie = new HttpCookie(keyvalueString);

cookieExpires = expires;

SetCookie(cookie);

}

public static void SetTripleDESEncryptedCookie(String key

String valueString)

{ //设置使用TripleDES加密后的Cookie

key = EncryptStringEncryptTripleDES(key);

valueString = EncryptStringEncryptTripleDES(valueString);

SetCookie(keyvalueString);

}

public static void SetTripleDESEncryptedCookie(String key

String valueStringDateTime expires)

{ //设置使用TripleDES加密后的Cookie并设置Cookie的有效时间

key = EncryptStringEncryptTripleDES(key);

valueString = EncryptStringEncryptTripleDES(valueString);

SetCookie(keyvalueStringexpires);

}

[] [] [] [] []

               

上一篇:使用ASP.Net加密Cookie[4]

下一篇:使用ASP.Net加密Cookie[5]