java - iTextPdf setEncryption 没有权限

标签 java encryption permissions itext

我正在使用这样的密码加密 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/

相关文章:

encryption - 如何在 Wildfly 中加密 bindCredential 密码?

iOS pdf 加密 256 位 AES

macos - OS X El Capitan 中的 "restricted"文件夹/文件

java - 什么是快速哈希,它将 UUID 映射到单位间隔?

java - 任务 ':app:processDebugGoogleServices' 执行失败

node.js - 通过 Node.Js 生成的管道 Amazon S3 下载流导致下载不完整

php - 如何更改 phpMyAdmin 中的权限

php - Magento权限-我无法通过Magento后端添加任何内容

java - Javafx 中的选择性子变换

java - 如何忽略系统默认 Locale 来检索 resourceBundle