读书人

System.Web.Security 在winform中是

发布时间: 2013-03-21 10:08:17 作者: rapoo

System.Web.Security 在winform中是什么命名空间呢
/// 加密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Encrypt(string Text,string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray=Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms=new System.IO.MemoryStream();
CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret=new StringBuilder();
foreach( byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}",b);
}
return ret.ToString();
}

以上代码在winform中,老是报如下错误,
错误2命名空间“System.Web”中不存在类型或命名空间名称“Security”。是否缺少程序集引用?E:\易飞外挂\易飞外挂\DBUtility\DESEncrypt.cs3853DBUtility
我想原因可能是System.Web 不能用于winform命名空间,那么在winform应该换成什么样对等的命名空间呢,谢谢高人

[解决办法]
添加了system.web的引用是可以找到的。
[解决办法]
首先确保你使用的是完整版的.net框架,在项目-属性-目标框架中,下拉选择的不是.net 4.0 client profile而是.net framework 4.0。然后在项目-添加引用中添加对system.web的引用。

读书人网 >C#

热点推荐