Reputation: 2704
I've ported over some C# to PHP as to which I thought was successful, it turns out that the PHP version of phpseclib
is appending extra random bytes to my result.
Here's my C# result in what it should be:
And here's my PHP result, as you can see it appends random bytes to the string.
The PHP functionality I'm using to decode is:
$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))));
The C# function that's decoding is:
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();
If anyone could point me in the right direction to prevent the extra bytes that'd be great, the other thing I should note is the amount of extra bytes vary based on the file which is decoded
Upvotes: 1
Views: 128
Reputation: 2704
It appears that removing $rijndael->disablePadding();
fixed the problem!
Upvotes: 1