Note that there are some explanatory texts on larger screens.

plurals
  1. POString from web.config AppSettings convert to byte[]
    primarykey
    data
    text
    <p>I seem to be struggling with this code and it would be appreciated if anyone can help.</p> <p>I have a string of data in web.config file in say the following format: 1, 3, 5, 7, 9, 11, 15, 17, 19.</p> <p>I need to pass the data into: <code>private static readonly byte[] Entropy</code> but I keep getting the error: <strong>The data is invalid</strong></p> <p>If I use the following: </p> <p><strong>private static readonly byte[] Entropy = { 1, 3, 5, 7, 9, 11, 15, 17, 19};</strong> it works Ok, so my problem seems to be converting the string into byte[].</p> <p>I have googled this problem on numerous sites (below are a few) </p> <p><a href="https://stackoverflow.com/questions/542766/c-sharp-convert-string-into-its-byte-equivalent">C# convert string into its byte[] equivalent</a></p> <p><a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/08e4553e-690e-458a-87a4-9762d8d405a6/how-to-convert-the-string-to-byte-in-c-" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/vstudio/en-US/08e4553e-690e-458a-87a4-9762d8d405a6/how-to-convert-the-string-to-byte-in-c-</a></p> <p><a href="https://stackoverflow.com/questions/16072709/converting-string-to-byte-array-in-c-sharp">Converting string to byte array in C#</a></p> <p><a href="http://www.chilkatsoft.com/faq/dotnetstrtobytes.html" rel="nofollow noreferrer">http://www.chilkatsoft.com/faq/dotnetstrtobytes.html</a></p> <p>But nothing seems to work.</p> <p>As stated above any help would be appreciated.</p> <pre><code>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); } </code></pre> <p>George</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload