/// 加密数据 
/// </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.cs 38 53 DBUtility
我想原因可能是System.Web 不能用于winform命名空间,那么在winform应该换成什么样对等的命名空间呢,谢谢高人

解决方案 »

  1.   

    添加了system.web的引用是可以找到的。
      

  2.   

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

  3.   


    我更改为 .net framework 4.0 ,跳出以下警告,为什么呢警告 1 未能解析引用的程序集“Maticsoft.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL”,因为它对不在当前目标框架“.NETFramework,Version=v4.0,Profile=Client”中的“System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”具有依赖关系。请删除对不在目标框架中的程序集的引用,或考虑重新确定项目的目标。 BLL
      

  4.   

    我更改为 .net framework 4.0 还有一个奇怪的事情
     DataTable dt = Maticsoft.DBUtility.DbHelperSQL.Query(cpsql).Tables[0]; 
    之前是OK的,更改完后,报如下错误错误 4 命名空间“Maticsoft.DBUtility”中不存在类型或命名空间名称“DbHelperSQL”。是否缺少程序集引用? E:\易飞外挂\易飞外挂\KAIERP\Form1.cs 106 48 HNERP我重新引用了,还是报这样子的错误 ,不明白 了
      

  5.   

    换了framework就不支持这个了呗
    换别的方法。