简体   繁体   English

在iText中使用setEncryption方法时是否可以仅设置所有者密码?

[英]Is it possible to set only owner password while using setEncryption method in iText?

Is it possible to set owner password as some value and user password as null or empty while using set encryption method of PdfWriter class? 使用PdfWriter类的设置加密方法时,是否可以将所有者密码设置为某个值,将用户密码设置为null或空?

I tried using code something like this 我尝试使用类似这样的代码

 String OWNER = "test";
 PdfWriter.setEncryption(null,OWNER.getBytes(),
                        PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);

I am able to open PDF generated with this code without entering any password. 我可以打开使用此代码生成的PDF,而无需输入任何密码。 BUT when I try to open it for editing with Adobe Acrobat, it opens the document in view mode and throws an error "This is secured document. Editing is not permitted." 但是,当我尝试将其打开以使用Adobe Acrobat进行编辑时,它将在查看模式下打开文档,并引发错误“此文档是安全文档。不允许编辑。” Screenshot of error: http://dropbox.com/s/1ef551o1z0n9ug1/editerror.jpg 错误的屏幕截图: http//dropbox.com/s/1ef551o1z0n9ug1/editerror.jpg

Any idea why this must be occurring? 知道为什么必须这样做吗? Am I doing something wrong? 难道我做错了什么?

On an additional note, 另外,

I have generated this new document with 我已经用

PdfWriter.setEncryption("test1".getBytes(),"test".getBytes(), 
                        PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128); 

Link: http://dropbox.com/s/8jeia7ezervrz18/Test_Success.pdf 链接: http//dropbox.com/s/8jeia7ezervrz18/Test_Success.pdf

I am able to view it after entering password as "test1" and able to edit it with password "test". 输入密码“ test1”并使用密码“ test”对其进行编辑后,便可以查看它。 I am not sure what exactly is going wrong when I pass USER as null in earlier case. 我不确定在较早的情况下将USER传递为null时究竟出了什么问题。

I am using following set of jars in my project 我在我的项目中使用以下罐子

  • itext-2.1.7.jar iText的 - 2.1.7.jar
  • bcmail-jdk14.jar bcmail-jdk14.jar
  • bcprov-jdk14.jar bcprov-jdk14.jar
    private static String user = "";
    private static String admin = "ADMIN";      
writer.setEncryption(admin.getBytes(), user.getBytes(),
                PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);

By using the above approach you can set admin password. 通过使用上述方法,您可以设置管理员密码。 There might be some problem in your classpath setting. 您的类路径设置中可能存在一些问题。 Use Mavel on Gardle for dependencies 使用MavelGardle依赖关系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM