fix bug with handling of more than 256 bytes

This commit is contained in:
Eliot Jones
2022-04-03 15:20:42 -04:00
parent 347259eaa5
commit 3ab0883cf3

View File

@@ -1,6 +1,7 @@
namespace UglyToad.PdfPig.Encryption
{
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
@@ -28,6 +29,11 @@
var buffer = new byte[256];
if (data.Length > 256)
{
Debugger.Break();
}
using (var decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV))
using (var input = new MemoryStream(data))
using (var output = new MemoryStream())
@@ -35,15 +41,15 @@
input.Seek(iv.Length, SeekOrigin.Begin);
using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
{
var offset = 0;
int read;
do
{
read = cryptoStream.Read(buffer, offset, buffer.Length - offset);
read = cryptoStream.Read(buffer, 0, buffer.Length);
output.Write(buffer, offset, read);
offset += read;
if (read > 0)
{
output.Write(buffer, 0, read);
}
} while (read > 0);
return output.ToArray();