Reputation: 521
I am working on decryption of a string (read from database) in PCL for Windows Phone 8 project. Below is the scenerio:
A solution having 3 projects, Windows phone UI, windows phone portable class library and class library.
Class Library Project is having a class StringDecryption which contains below code:
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";
}
}
}
I am referencing the dll from this class library to Portable class library and when calling method Decryption from this library it is throwing System.IO.FileNotFoundException but same is running fine when I am calling Getname method. Full message from exception is Could not load file or assembly 'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Is there Any way to resolve this issue or any other way to encrypt or decrypt a string in PCL??
Thanks in advance.
Upvotes: 3
Views: 776
Reputation: 16744
It sounds like you are referencing the "Class Library" from a "Portable Class Library". This is not supported- the class library only supports one platform (probably the full .NET Framework) so it won't run on the other platforms your Portable Class Library targets.
Is there Any way to resolve this issue or any other way to encrypt or decrypt a string in PCL??
I'd recommend looking at the PCL Crypto library.
For some more general information that I think would help you, see my blog post: How to Make Portable Class Libraries Work for You
Upvotes: 1