@@ -60,7 +60,6 @@ This file is part of the iText (R) project.
60
60
import org .bouncycastle .jce .provider .BouncyCastleProvider ;
61
61
import org .junit .Assert ;
62
62
import org .junit .BeforeClass ;
63
- import org .junit .Ignore ;
64
63
import org .junit .Rule ;
65
64
import org .junit .Test ;
66
65
import org .junit .experimental .categories .Category ;
@@ -412,14 +411,69 @@ public void encryptWithPasswordAes128EmbeddedFilesOnly() throws IOException, Gen
412
411
public void encryptAes256Pdf2NotEncryptMetadata () throws InterruptedException , IOException , XMPException {
413
412
String filename = "encryptAes256Pdf2NotEncryptMetadata.pdf" ;
414
413
int encryptionType = EncryptionConstants .ENCRYPTION_AES_256 | EncryptionConstants .DO_NOT_ENCRYPT_METADATA ;
415
- encryptWithPassword (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
414
+ encryptWithPassword (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION , true );
415
+ }
416
+
417
+ @ Test
418
+ public void encryptAes256EncryptedStampingPreserve () throws InterruptedException , IOException , XMPException {
419
+ String filename = "encryptAes256EncryptedStampingPreserve.pdf" ;
420
+ String src = sourceFolder + "encryptedWithPlainMetadata.pdf" ;
421
+ String out = destinationFolder + filename ;
422
+
423
+ PdfDocument pdfDoc = new PdfDocument (
424
+ new PdfReader (src , new ReaderProperties ().setPassword (OWNER )),
425
+ new PdfWriter (out , new WriterProperties ()),
426
+ new StampingProperties ().preserveEncryption ());
427
+
428
+ pdfDoc .close ();
429
+
430
+ CompareTool compareTool = new CompareTool ().enableEncryptionCompare ();
431
+ String compareResult = compareTool .compareByContent (out , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" , USER , USER );
432
+ if (compareResult != null ) {
433
+ Assert .fail (compareResult );
434
+ }
435
+ }
436
+
437
+ @ Test
438
+ public void encryptAes256EncryptedStampingUpdate () throws InterruptedException , IOException , XMPException {
439
+ String filename = "encryptAes256EncryptedStampingUpdate.pdf" ;
440
+ String src = sourceFolder + "encryptedWithPlainMetadata.pdf" ;
441
+ String out = destinationFolder + filename ;
442
+
443
+ PdfDocument pdfDoc = new PdfDocument (
444
+ new PdfReader (src , new ReaderProperties ().setPassword (OWNER )),
445
+ new PdfWriter (out , new WriterProperties ()
446
+ .setStandardEncryption (USER , OWNER , EncryptionConstants .ALLOW_PRINTING , EncryptionConstants .STANDARD_ENCRYPTION_40 )),
447
+ new StampingProperties ());
448
+
449
+ pdfDoc .close ();
450
+
451
+ CompareTool compareTool = new CompareTool ().enableEncryptionCompare ();
452
+ String compareResult = compareTool .compareByContent (out , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" , USER , USER );
453
+ if (compareResult != null ) {
454
+ Assert .fail (compareResult );
455
+ }
456
+ }
457
+
458
+ @ Test
459
+ public void encryptAes256FullCompression () throws InterruptedException , IOException , XMPException {
460
+ String filename = "encryptAes256FullCompression.pdf" ;
461
+ int encryptionType = EncryptionConstants .ENCRYPTION_AES_256 ;
462
+ encryptWithPassword (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION , true );
416
463
}
417
464
418
465
public void encryptWithPassword (String filename , int encryptionType , int compression ) throws XMPException , IOException , InterruptedException {
466
+ encryptWithPassword (filename , encryptionType , compression , false );
467
+ }
468
+
469
+ public void encryptWithPassword (String filename , int encryptionType , int compression , boolean fullCompression ) throws XMPException , IOException , InterruptedException {
419
470
String outFileName = destinationFolder + filename ;
420
471
int permissions = EncryptionConstants .ALLOW_SCREENREADERS ;
421
472
PdfWriter writer = new PdfWriter (outFileName ,
422
- new WriterProperties ().setStandardEncryption (USER , OWNER , permissions , encryptionType ).addXmpMetadata ());
473
+ new WriterProperties ()
474
+ .setStandardEncryption (USER , OWNER , permissions , encryptionType )
475
+ .addXmpMetadata ()
476
+ .setFullCompressionMode (fullCompression ));
423
477
writer .setCompressionLevel (compression );
424
478
PdfDocument document = new PdfDocument (writer );
425
479
document .getDocumentInfo ().setAuthor (author ).
0 commit comments