我正在使用这样的密码加密 pdf:
public static void main(String[] args) throws DocumentException, MalformedURLException, IOException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("zrsz.pdf"));
writer.setEncryption("ownerPass".getBytes(), "userPass".getBytes(), PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
writer.createXmpMetadata();
document.open();
document.add(new Paragraph("This is create PDF with Password demo."));
document.close();
System.out.println("Done");
}
但我找不到向此 setEncryption
方法提供“无权限”参数的方法:
public void setEncryption(byte[] userPassword,
byte[] ownerPassword,
int permissions,
int encryptionType)
这可能吗?我想将对该文件的访问限制在最低限度。我只是用它来读取 secret 数据。
提前致谢!
最佳答案
根据手册,您可以使用以下所有内容作为 Docs说
Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting
使用用户密码打开文档时允许执行上述所有操作。因此,您有一个安全措施,只有输入有效凭据(密码)的用户才能操作它。
关于java - iTextPdf setEncryption 没有权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51957370/