我正在用这样的密码加密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)
有可能吗?我想限制对该文件的访问。我只是用它来读取机密数据。
谢谢!
答案 0 :(得分:3)
根据手册,您可以使用Docs所说的所有内容
设置此文档的加密选项。 userPassword和 ownerPassword可以为null或长度为零。在这种情况下 ownerPassword替换为随机字符串。的开放权限 该文档可以是AllowPrinting,AllowModifyContents,AllowCopy, AllowModifyAnnotations,AllowFillIn,AllowScreenReaders,AllowAssembly 和AllowDegradedPrinting
使用用户密码打开文档时,允许上述所有操作。因此,您有一项安全措施,只有输入有效凭据(密码)的用户才能操作它。