2016-04-07 22 views
0

私は解読のためにBouncy Castleライブラリを使用しようとしています。しかし、解読された文字列は正しくありません。私は値Aa1ŽYY445Loを得ているが、正しい値はAa11YY445LLでなければならない。私が間違っていることは何ですか? http://rc4.online-domain-tools.com/の文字列を復号しようとすると正しい結果が得られません。C#のBouncy Castle RC4アルゴリズムを使用した文字列の復号化

コードサンプル:

string textToDecrypt = HexDumper.FromHex("E5497380DC724B28284D80"); 
var key = Encoding.UTF8.GetBytes("heslo"); 
var cipher = new RC4Engine(); 
cipher.Init(true, new KeyParameter(key)); 

byte[] inBytes = UTF8Encoding.GetEncoding(1252).GetBytes(textToDecrypt); 
byte[] outBuffer = new byte[1024 * 4]; 
cipher.ProcessBytes(inBytes, 0, inBytes.Length, outBuffer, 0); 

// Output must be 41 61 31 31 59 59 34 34 35 4c 4c -> Aa11YY445LL 
var textDecrypted = ASCIIEncoding.GetEncoding(1252).GetString(outBuffer); 
int indexOf0 = textDecrypted.IndexOf("\0"); 
if (indexOf0 > 0) 
{ 
    textDecrypted = textDecrypted.Substring(0, indexOf0); 
    MessageBox.Show(textDecrypted); 
} 

public static string FromHex(string hexString) 
{ 
    string StrValue = ""; 
    while (hexString.Length > 0) 
    { 
     StrValue += System.Convert.ToChar(System.Convert.ToUInt32(hexString.Substring(0, 2), 16)).ToString(); 
     hexString = hexString.Substring(2, hexString.Length - 2); 
    } 
    return StrValue; 
} 

答えて

2

問題は、あなたのFromHex機​​能です。

先頭の答えをHow can I convert a hex string to a byte array?から入れ替え、正しい結果を得ました。

FromHexで何が問題になっているのかはわかりません。

関連する問題