diff options
author | emusic <emina.music@egiz.gv.at> | 2018-03-21 13:06:24 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2018-03-21 13:34:05 +0100 |
commit | e49eb5e433767386a09732f5942b6425098b511b (patch) | |
tree | 43fb29542b0ce702a0dbfbed8b4ead25f7872ac2 /pdf-as-cli/src/main/java | |
parent | f60b607e56700bb6b3130c2ad549b0b1c14267a4 (diff) | |
download | pdf-as-4-e49eb5e433767386a09732f5942b6425098b511b.tar.gz pdf-as-4-e49eb5e433767386a09732f5942b6425098b511b.tar.bz2 pdf-as-4-e49eb5e433767386a09732f5942b6425098b511b.zip |
changes regarding protection, bug fix, thread safe
Diffstat (limited to 'pdf-as-cli/src/main/java')
-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"); } } |