我正在尝试解密在 Delphi 中使用 Cipher1 3.0 加密的 C# 中的一个字符串,来自 Delphi 加密纲要的第一部分。
我使用 TCipher_Rijndael。
我加密的字符串是:this-is-a-test-example
密码:通过
加密值是:iKBC8kX4ZEk4A1pCj6jwEegqjpxhqw==
当我尝试在 C# 中解密时,我收到错误:要解密的数据长度无效。
有人遇到同样的问题吗?有什么解决办法吗?
这是c#中的解密方法:
public static byte[] Decrypt(byte[] cipherData,
byte[] Key, byte[] IV)
{
MemoryStream ms = new MemoryStream();
Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
CryptoStream cs = new CryptoStream(ms,
alg.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(cipherData, 0, cipherData.Length);
cs.Close();
byte[] decryptedData = ms.ToArray();
return decryptedData;
}
这是 Delphi 中的加密代码:
with TCipher_Rijndael.Create('pass', nil) do
begin
memo2.lines.add ( CodeString( 'this-is-a-test-example' , paEncode, fmtDEFAULT));
Free;
end;
Thanks.