diff options
Diffstat (limited to 'pdf-as-cli/src/main')
-rw-r--r-- | pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java | 8 |
1 files changed, 6 insertions, 2 deletions
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"); } } |