From e49eb5e433767386a09732f5942b6425098b511b Mon Sep 17 00:00:00 2001 From: emusic Date: Wed, 21 Mar 2018 13:06:24 +0100 Subject: changes regarding protection, bug fix, thread safe --- pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pdf-as-cli/src/main/java/at/gv/egiz/pdfas') diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java index f6df73d5..f3e1d2c8 100644 --- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java +++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java @@ -26,6 +26,8 @@ package at.gv.egiz.pdfas.cli; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.nio.charset.StandardCharsets; +import java.security.SecureRandom; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; @@ -457,18 +459,20 @@ public class Main { if(configuration.hasValue(DEFAULT_CONFIG_PROTECT_PDF) && IConfigurationConstants.TRUE.equalsIgnoreCase(configuration.getValue(DEFAULT_CONFIG_PROTECT_PDF))) { + SecureRandom random = new SecureRandom(); + byte seed[] = random.generateSeed(50); + String ownerPassword = new String(seed, StandardCharsets.UTF_8); PDDocument document = PDDocument.load(outputPdfFile); AccessPermission accessPermission = new AccessPermission(); accessPermission.setCanExtractContent(false); accessPermission.setCanExtractForAccessibility(true); - StandardProtectionPolicy spp = new StandardProtectionPolicy("1234","",accessPermission); + StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword,"",accessPermission); spp.setEncryptionKeyLength(128); spp.setPermissions(accessPermission); document.protect(spp); document.save(outputPdfFile); document.close(); //accessPermission.setCanModify(false); - // accessPermission.setReadOnly(); logger.info("Added Protection Parameters"); } } -- cgit v1.2.3