Skip to content

Commit 29c7f13

Browse files
BlackEgoistiText-CI
authored andcommitted
Fix bytes retrieval from pdf byte string during PdfEncryption init
DEVSIX-526 Autoported commit. Original commit hash: [8b5d9497c]
1 parent ead0960 commit 29c7f13

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

itext.tests/itext.kernel.tests/itext/kernel/crypto/PdfEncryptionTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,27 @@ public virtual void EncryptAes256Pdf2Permissions() {
611611
CompareEncryptedPdf(filename);
612612
}
613613

614+
/// <exception cref="System.Exception"/>
615+
[NUnit.Framework.Test]
616+
public virtual void EncryptWithPasswordAes128NoMetadataCompression() {
617+
String srcFilename = "srcEncryptWithPasswordAes128NoMetadataCompression.pdf";
618+
PdfReader reader = new PdfReader(sourceFolder + srcFilename, new ReaderProperties());
619+
WriterProperties props = new WriterProperties().SetStandardEncryption("superuser".GetBytes(), "superowner"
620+
.GetBytes(), EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128 | EncryptionConstants
621+
.DO_NOT_ENCRYPT_METADATA);
622+
String outFilename = "encryptWithPasswordAes128NoMetadataCompression.pdf";
623+
PdfWriter writer = new PdfWriter(destinationFolder + outFilename, props);
624+
PdfDocument pdfDoc = new PdfDocument(reader, writer);
625+
pdfDoc.Close();
626+
CompareTool compareTool = new CompareTool();
627+
compareTool.EnableEncryptionCompare();
628+
compareTool.GetOutReaderProperties().SetPassword("superowner".GetBytes());
629+
compareTool.GetCmpReaderProperties().SetPassword("superowner".GetBytes());
630+
String outPdf = destinationFolder + outFilename;
631+
String cmpPdf = sourceFolder + "cmp_" + outFilename;
632+
NUnit.Framework.Assert.IsNull(compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"));
633+
}
634+
614635
/// <exception cref="iText.Kernel.XMP.XMPException"/>
615636
/// <exception cref="System.IO.IOException"/>
616637
/// <exception cref="System.Exception"/>

itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected internal virtual void InitCryptoIfSpecified(PdfVersion version) {
186186
EncryptionProperties encryptProps = properties.encryptionProperties;
187187
if (properties.IsStandardEncryptionUsed()) {
188188
crypto = new PdfEncryption(encryptProps.userPassword, encryptProps.ownerPassword, encryptProps.standardEncryptPermissions
189-
, encryptProps.encryptionAlgorithm, ByteUtils.GetIsoBytes(this.document.GetOriginalDocumentId().ToString
189+
, encryptProps.encryptionAlgorithm, ByteUtils.GetIsoBytes(this.document.GetOriginalDocumentId().GetValue
190190
()), version);
191191
}
192192
else {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f0e758a49c8c1bb60c79dfc5da156ecf6a2e89cb
1+
8b5d9497c4ebf8ac62a14344b7a1acafaf960356

0 commit comments

Comments
 (0)