Skip to content

Commit 68e48d0

Browse files
Arnaud TAMAILLONBobLd
Arnaud TAMAILLON
authored andcommitted
Support decrypting AES data where only IV is present
1 parent 4f2a097 commit 68e48d0

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/UglyToad.PdfPig.Tests/Integration/EncryptedDocumentTests.cs

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public void CanReadDocumentWithUEAsString()
5353
Assert.NotNull(document.Information.Producer);
5454
}
5555
}
56+
57+
[Fact]
58+
public void CanReadDocumentWithEmptyStringEncryptedWithAESEncryptionAndOnlyIV()
59+
{
60+
using (var document = PdfDocument.Open(IntegrationHelpers.GetSpecificTestDocumentPath("r4_aes_empty_string.pdf")))
61+
{
62+
Assert.Empty(document.Information.Producer);
63+
}
64+
}
5665

5766
private static string GetPath() => IntegrationHelpers.GetSpecificTestDocumentPath(FileName);
5867
}

src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ public static byte[] Decrypt(byte[] data, byte[] finalKey)
2727
aes.IV = iv;
2828

2929
#if NET8_0_OR_GREATER
30-
return aes.DecryptCbc(data.AsSpan(iv.Length), iv, PaddingMode.PKCS7);
30+
var encryptedData = data.AsSpan(iv.Length);
31+
if (encryptedData.IsEmpty)
32+
{
33+
return [];
34+
}
35+
return aes.DecryptCbc(encryptedData, iv, PaddingMode.PKCS7);
3136
#else
3237
var buffer = new byte[256];
3338

0 commit comments

Comments
 (0)