如何阅读使用未知的随机所有者密码创建的PDF? [英] How to read PDFs created with an unknown random owner password?

查看:510
本文介绍了如何阅读使用未知的随机所有者密码创建的PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求是一次处理一批PDF,并且成功使用用户密码加密每一个。

Requirement is to process a batch of PDF's one at a time and on success encrypt each of them with an user password.

但是,这些PDF以前是用加密的随机生成的动态所有者密码(不知道任何人)以防止任何编辑。

However, these PDF's were encrypted previously with randomly generated dynamic owner password (not know to any one) to prevent any edits.

我使用 iText 用于加密,如下所示:

I use iText for encryption as shown below:

byte[] userPass = "user".getBytes();
byte[] ownerPass = "owner".getBytes();
PdfReader reader = new PdfReader("Misc.pdf");

PdfStamper stamper = new PdfStamper(reader,
            new FileOutputStream("Processed_Encrypted.pdf"));
stamper.setEncryption(userPass, ownerPass,
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128
        | PdfWriter.DO_NOT_ENCRYPT_METADATA);
stamper.close();
reader.close();

但此代码抛出 com.itextpdf.text.exceptions.BadPasswordException: PdfReader未使用所有者密码打开

有关如何解决此错误/绕过所有者密码的指导吗?

Can some one guide on how to resolve this error / bypass owner password?

在此,我想明确表示我们合法拥有这些PDF,因此不会犯下任何犯罪/黑客行为。

Here I would like to make clear that we legally own these PDFs, so no crime / hacking is committed.

PS :解决方案不仅限于iText,也可以使用任何其他Java库(免费或许可)。

P.S.: Solution isn't limited to iText, can use any other Java library (Free or licensed) too.

推荐答案

PdfReader 有一个未记录的静态布尔值名为 unethicalreading 的变量。出于显而易见的原因,此变量默认设置为 false 。您可以将此变量设置为true,如下所示:

PdfReader has an undocumented static boolean variable named unethicalreading. For obvious reasons, this variable is set to false by default. You could set this variable to true like this:

PdfReader.unethicalreading = true;

从现在开始,PdfReader将忽略所有者密码的存在。如果有用户密码,它只会抛出异常。

From now on, PdfReader will ignore the presence of an owner password. It will only throw an exception if a user password is in place.

使用此风险需要您自担风险。

Use this at your own risk.

这篇关于如何阅读使用未知的随机所有者密码创建的PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆