How to read PDFs created with an unknown random owner password?(如何阅读使用未知随机所有者密码创建的 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.
However, these PDF's were encrypted previously with randomly generated dynamic owner password (not know to any one) to prevent any edits.
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();
But this code throws an 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.
P.S.: Solution isn't limited to iText, can use any other Java library (Free or licensed) too.
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;
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何阅读使用未知随机所有者密码创建的 PDF?
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01