0

私はこのコードに苦労しているようです。誰か助けていただければ幸いです。

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}; それは問題なく動作するので、私の問題は文字列をバイト[]に変換しているようです。

私はこの問題を多数のサイトでグーグル検索しました(以下はいくつかです)

C# 文字列をその byte[] に相当するものに変換する

http://social.msdn.microsoft.com/Forums/vstudio/en-US/08e4553e-690e-458a-87a4-9762d8d405a6/how-to-convert-the-string-to-byte-in-c-

C#で文字列をバイト配列に変換する

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);
        }

ジョージ

4

1 に答える 1

1

あなたはできる:

string Entropy = "1, 3, 5, 7, 9, 11, 15, 17, 19";
var parts = Entropy.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
byte[] bytes = Array.ConvertAll(parts, p => byte.Parse(p));

byte.Parseスペースを「食べ」、無視します。AB16 進数スタイルの数字 ( 、ただし、なしでは使用できない0xため、 no 0xAB) を使用できないことに注意してください。次のものが必要です。

byte[] bytes = Array.ConvertAll(parts, p => byte.Parse(p, NumberStyles.HexNumber));

しかし、それは非16進数を受け入れません:-)

于 2013-09-02T14:15:36.520 に答える