java 如何阅读使用未知的随机所有者密码创建的 PDF?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15955620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to read PDFs created with an unknown random owner password?
提问by Bond - Java Bond
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,并在成功时使用用户密码对每个 PDF 进行加密。
However, these PDF's were encrypted previously with randomly generated dynamic owner password (not know to any one)to prevent any edits.
但是,这些 PDF 以前是用随机生成的动态所有者密码(任何人都不知道)加密的,以防止任何编辑。
I use iTextfor encryption as shown below:
我使用iText进行加密,如下所示:
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();
But this code throws an com.itextpdf.text.exceptions.BadPasswordException: PdfReader not opened with owner password
但是这段代码抛出了一个 com.itextpdf.text.exceptions.BadPasswordException: PdfReader not opened with owner password
Can some one guide on how to resolve this error / bypass owner password?
有人可以指导如何解决此错误/绕过所有者密码吗?
Here I would like to make clear that we legally own these PDFs, so no crime / hacking is committed.
在这里,我想明确指出,我们合法拥有这些 PDF,因此没有犯罪/黑客行为。
P.S.: Solution isn't limited to iText, can use any other Java library (Free or licensed) too.
PS:解决方案不限于 iText,也可以使用任何其他 Java 库(免费或许可)。
回答by Bruno Lowagie
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
有一个static boolean
名为的未记录变量unethicalreading
。出于显而易见的原因,此变量false
默认设置为。您可以像这样将此变量设置为 true:
PdfReader.unethicalreading = true;
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.
从现在开始,PdfReader 将忽略所有者密码的存在。如果用户密码到位,它只会抛出异常。
Use this at your own risk.
使用它需要您自担风险。