【发布时间】:2014-07-04 06:25:48
【问题描述】:
我正在为 Windows Phone 8 项目的 PCL 中的字符串解密(从数据库中读取)。下面是场景:
一个包含 3 个项目的解决方案,Windows phone UI、windows phone 便携类库和类库。
类库项目有一个类 StringDecryption,其中包含以下代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace DecryptString
{
public class StringDecryption
{
public string Decryption(string encryptedTExt)
{
var protectedText = this.ReadEncryptedData(encryptedTExt);
// Decrypt the text by using the Unprotect method.
var textByte = ProtectedData.Unprotect(protectedText, null, DataProtectionScope.CurrentUser);
// Convert the text from byte to string and display it in the text box.
return Encoding.UTF8.GetString(textByte, 0, textByte.Length);
}
public byte[] ReadEncryptedData(string text)
{
var reader = new StreamReader(text).BaseStream;
var textArray = new byte[reader.Length];
reader.Read(textArray, 0, textArray.Length);
reader.Close();
return textArray;
}
public string Getname()
{
return "MyName";
}
}
}
我将这个类库中的 dll 引用到可移植类库中,当从这个库调用 Decryption 方法时,它抛出 System.IO.FileNotFoundException 但是当我调用 时同样运行良好>Getname 方法。来自异常的完整消息是无法加载文件或程序集 'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一。系统找不到指定的文件。
有什么方法可以解决这个问题,或者有什么其他方法可以加密或解密 PCL 中的字符串吗??
提前致谢。
【问题讨论】:
标签: c# c#-4.0 windows-phone-8 portable-class-library class-library