我已经将某些C#移植到了我认为很成功的PHP上,结果发现phpseclib
的PHP版本正在向结果附加额外的随机字节。
这是我的C#结果:
这是我的PHP结果,如您所见,它会将随机字节附加到字符串中。
我用来解码的PHP功能是:
$rijndael = new Rijndael();
$rijndael->setKey(hex2bin($rgbKey));
$rijndael->setIV(hex2bin($rgbIv));
$rijndael->setKeyLength(256);
$rijndael->setBlockLength(128);
$rijndael->disablePadding();
$result = $rijndael->decrypt(rtrim(hex2bin(implode("", $hexdata))));
正在解码的C#函数是:
int num2 = 0;
int count1 = rijndaelManaged.BlockSize / 8;
byte[] buffer4 = new byte[count1];
fileStream.Seek((long)Start, SeekOrigin.Begin);
using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Write)) {
while (fileStream.Position < fileStream.Length - 128L) {
int count2 = fileStream.Read(buffer4, 0, count1);
num2 += count2;
cryptoStream.Write(buffer4, 0, count2);
if (count2 <= 0)
break;
}
cryptoStream.FlushFinalBlock();
cryptoStream.Close();
}
fileStream.Close();
如果有人能指出正确的方向来防止多余的字节,那我还要注意的是,多余的字节数会根据解码的文件而有所不同
答案 0 :(得分:1)
删除$rijndael->disablePadding();
似乎可以解决问题!