C#.Net Session操作 Key使用MD5加密,Value使用DES加密
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace Pub.Class
{
/// <summary>
/// Session操作类
/// </summary>
public class Session2
{
#region Set
/// <summary>
/// 设置Session值
/// </summary>
/// <param name="InfoName">Session名称</param>
/// <param name="InfoValue">Session名称对应的值</param>
static public void Set(String InfoName, String InfoValue) {
string key = "9cf8d21d394a8919d2f9706dfdc6421e";
InfoName = (key + InfoName).MD5();
InfoValue = InfoValue.DESEncode(key);
HttpContext.Current.Session[InfoName] = InfoValue;
if (InfoValue.Length == 0) HttpContext.Current.Session.Remove(InfoName);
}
#endregion
#region Get
/// <summary>
/// 取Session值
/// </summary>
/// <param name="InfoName">Session名称</param>
/// <returns>Session名称对应的值</returns>
static public String Get(String InfoName) {
string _Value = string.Empty;
string key = "9cf8d21d394a8919d2f9706dfdc6421e";
InfoName = (key + InfoName).MD5();
if (HttpContext.Current.Session[InfoName] != null) { _Value = Convert.ToString(HttpContext.Current.Session[InfoName]); _Value = _Value.DESDecode(key); }
return _Value;
}
#endregion
}
}
开源:
https://github.com/hcxiong 欢迎收藏:)