diff --git a/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs b/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs index 6a07a911..1ae27525 100644 --- a/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs +++ b/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs @@ -23,7 +23,9 @@ namespace UglyToad.PdfPig.Tests.Encryption var output = AesEncryptionHelper.Decrypt(data, key); - Assert.Equal("D:20180808103317-07'00'", OtherEncodings.BytesAsLatin1String(output)); + var actual = OtherEncodings.BytesAsLatin1String(output); + + Assert.Equal("D:20180808103317-07'00'", actual); } } } diff --git a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs index 3e4cd7b6..7f4a246d 100644 --- a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs +++ b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs @@ -35,16 +35,16 @@ input.Seek(iv.Length, SeekOrigin.Begin); using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read)) { + var offset = 0; int read; - while ((read = cryptoStream.Read(buffer, 0, buffer.Length)) != -1) + do { - output.Write(buffer, 0, read); + read = cryptoStream.Read(buffer, offset, buffer.Length - offset); - if (read < buffer.Length) - { - break; - } - } + output.Write(buffer, offset, read); + + offset += read; + } while (read > 0); return output.ToArray(); }