我有一个加密程序,做成了类,我应用在VS2012 并且是 .Net 4.5的Winform里不会报错,正常使用
应用在WindowsCE设备里,就会报错,在VS2008里也添加System.Web的引用
就会报错,报错如下
未能从程序集“mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC”中加载类型“System.Threading.ReaderWriterLock”。
具体代码:
using System;
using System.Security.Cryptography;
using System.Text;
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();
}
错误图片:
