I seem to be struggling with this code and it would be appreciated if anyone can help.
I have a string of data in web.config file in say the following format: 1, 3, 5, 7, 9, 11, 15, 17, 19.
I need to pass the data into: private static readonly byte[] Entropy
but I keep getting the error: The data is invalid
If I use the following:
private static readonly byte[] Entropy = { 1, 3, 5, 7, 9, 11, 15, 17, 19}; it works Ok, so my problem seems to be converting the string into byte[].
I have googled this problem on numerous sites (below are a few)
C# convert string into its byte[] equivalent
Converting string to byte array in C#
http://www.chilkatsoft.com/faq/dotnetstrtobytes.html
But nothing seems to work.
As stated above any help would be appreciated.
private static readonly string WKey = ConfigurationManager.AppSettings["Entropy"];
private static readonly byte[] Entropy = WKey;
public static string DecryptDataUsingDpapi(string encryptedData)
{
byte[] dataToDecrypt = Convert.FromBase64String(encryptedData);
byte[] originalData = ProtectedData.Unprotect(dataToDecrypt, Entropy, DataProtectionScope.CurrentUser);
return Encoding.Unicode.GetString(originalData);
}
George