私はこのコードに苦労しているようです。誰か助けていただければ幸いです。
web.config ファイルには、1、3、5、7、9、11、15、17、19 という形式のデータ文字列があります。
データを渡す必要があります:private static readonly byte[] Entropy
しかし、エラーが発生し続けます:データが無効です
以下を使用する場合:
private static readonly byte[] Entropy = { 1, 3, 5, 7, 9, 11, 15, 17, 19}; それは問題なく動作するので、私の問題は文字列をバイト[]に変換しているようです。
私はこの問題を多数のサイトでグーグル検索しました(以下はいくつかです)
http://www.chilkatsoft.com/faq/dotnetstrtobytes.html
しかし、何も機能していないようです。
上記のように、どんな助けでも大歓迎です。
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);
}
ジョージ