我正在使用PDFBOX - 1.8.13,似乎PDF安全不能按预期工作。如果设置了所有者密码且用户密码不是,则PDFBOX允许解密我的PDF文件,如果我不提供所有者密码。请帮我在哪里做错了。PDFBOX安全不起作用
加密我的PDF文件中的代码:
PDDocument document = PDDocument.load(new File("/home/dummy/dummy.pdf"),null);
AccessPermission perms = new AccessPermission();
perms.setCanAssembleDocument(false);;
perms.setCanExtractContent(false);
perms.setCanModify(false);
perms.setCanModifyAnnotations(false);
perms.setCanExtractForAccessibility(false);
perms.setCanFillInForm(false);
perms.setCanPrint(false);
perms.setReadOnly();
perms.setCanPrintDegraded(false);
perms.setCanExtractForAccessibility(false);
document.setAllSecurityToBeRemoved(false);
StandardProtectionPolicy policy = new StandardProtectionPolicy("AdminPasswordTest", "", perms);
policy.setPermissions(perms);
document.protect(policy);
document.save("/home/dummy/dummy_secured.pdf");
document.close();
解密我PDF的代码
PDDocument doc = PDDocument.load("/home/dummy/dummy_secured.pdf", true);
if (doc.isEncrypted()) { //remove the security before adding protections
doc.decrypt(""); //This should not be DECRYPTED because owner password is not provided
doc.setAllSecurityToBeRemoved(true); //This user is not provided this permissions
}
doc.save("/home/dummy/dummy_decrypted.pdf");
doc.close();
另请参阅:https://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt –