在保存文件之前从 StandardProtectionPolicy 获取散列密码 - 使用 Apache PDFBox
Getting hashed Password from StandardProtectionPolicy before saving File - using Apache PDFBox
我正在开发一个程序来暴力破解 PDF 文件。
现在我无法在保存 PDDocument 之前读取经过哈希处理的所有者密码。问题是一次又一次地保存文件然后从 StandardProtectionPolicy 中读出哈希密码要慢得多。
这是我正在使用的代码。
//creating new Document
PDDocument doc1 = new PDDocument();
//creating StandardProtectionPolicy
StandardProtectionPolicy spp = new StandardProtectionPolicy("somepassword", "", new AccessPermission());
spp.setEncryptionKeyLength(128);
//setting the StandardProtectPolicy
doc1.protect(spp);
doc1.save("C:\Users\user\Desktop\filename.pdf");
//reading out the hash
String hash = new String(doc1.getEncryption().getOwnerKey());
//closing the PDDocument
doc1.close();
所以我的问题是,我是否可以在不保存甚至不创建 PDDocument 的情况下读出散列。如果我只是不保存文档,它就不起作用。
感谢您的帮助。
卢卡
我找到了解决方案。
所以对于其他想知道的人:
PDDocument doc1 = new PDDocument();
StandardProtectionPolicy spp = new StandardProtectionPolicy(String.valueOf(i), "", new AccessPermission());
spp.setEncryptionKeyLength(128);
doc1.protect(spp);
不需要保存了
//doc1.save("C:\Users\user\Desktop\working.pdf");
StandardSecurityHandler sh = new StandardSecurityHandler(spp);
sh.prepareDocumentForEncryption(doc1);
hash = new String(doc1.getEncryption().getOwnerKey());
我正在开发一个程序来暴力破解 PDF 文件。
现在我无法在保存 PDDocument 之前读取经过哈希处理的所有者密码。问题是一次又一次地保存文件然后从 StandardProtectionPolicy 中读出哈希密码要慢得多。
这是我正在使用的代码。
//creating new Document
PDDocument doc1 = new PDDocument();
//creating StandardProtectionPolicy
StandardProtectionPolicy spp = new StandardProtectionPolicy("somepassword", "", new AccessPermission());
spp.setEncryptionKeyLength(128);
//setting the StandardProtectPolicy
doc1.protect(spp);
doc1.save("C:\Users\user\Desktop\filename.pdf");
//reading out the hash
String hash = new String(doc1.getEncryption().getOwnerKey());
//closing the PDDocument
doc1.close();
所以我的问题是,我是否可以在不保存甚至不创建 PDDocument 的情况下读出散列。如果我只是不保存文档,它就不起作用。
感谢您的帮助。
卢卡
我找到了解决方案。 所以对于其他想知道的人:
PDDocument doc1 = new PDDocument();
StandardProtectionPolicy spp = new StandardProtectionPolicy(String.valueOf(i), "", new AccessPermission());
spp.setEncryptionKeyLength(128);
doc1.protect(spp);
不需要保存了
//doc1.save("C:\Users\user\Desktop\working.pdf");
StandardSecurityHandler sh = new StandardSecurityHandler(spp);
sh.prepareDocumentForEncryption(doc1);
hash = new String(doc1.getEncryption().getOwnerKey());