关于System.Security.Cryptography的错误问题

wmycom 2015-06-09 02:07:39
我有一个加密程序,做成了类,我应用在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();
}


错误图片:
...全文
1103 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
於黾 2015-06-09
  • 打赏
  • 举报
回复
using System.Security.Cryptography; public string GetMd5(string strPwd) { using (MD5 md5 = MD5.Create()) { byte[] byteHash = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(strPwd)); string strRes = BitConverter.ToString(byteHash).Replace("-", ""); return strRes.ToUpper(); } } MD5而已,有那么复杂吗,还要引用system.web,这跟web有啥关系
wmycom 2015-06-09
  • 打赏
  • 举报
回复
引用 3 楼 Z65443344 的回复:
我先确认一件事 所谓做成类 其实就是一段代码呗 并没有做成dll是吧 那么应该是wince里不支持system.web
对,只是一段代码。WINCE 不支持的话,我怎么做加密啊
於黾 2015-06-09
  • 打赏
  • 举报
回复
我先确认一件事 所谓做成类 其实就是一段代码呗 并没有做成dll是吧 那么应该是wince里不支持system.web
wmycom 2015-06-09
  • 打赏
  • 举报
回复
引用 1 楼 Z65443344 的回复:
版本不一致 2008最多支持3.5,不支持4.5 而且2008以上版本不支持wince 所以你需要调用支持3.5的dll
我知道,WINCE 只能用VS2008 来开发,应该是2.0的,那这个代码不支持2.0么??
於黾 2015-06-09
  • 打赏
  • 举报
回复
版本不一致 2008最多支持3.5,不支持4.5 而且2008以上版本不支持wince 所以你需要调用支持3.5的dll

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧