aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-cli
diff options
context:
space:
mode:
authoremusic <emina.music@egiz.gv.at>2018-03-21 13:06:24 +0100
committeremusic <emina.music@egiz.gv.at>2018-03-21 13:34:05 +0100
commite49eb5e433767386a09732f5942b6425098b511b (patch)
tree43fb29542b0ce702a0dbfbed8b4ead25f7872ac2 /pdf-as-cli
parentf60b607e56700bb6b3130c2ad549b0b1c14267a4 (diff)
downloadpdf-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')
-rw-r--r--pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java8
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");
}
}