我正在使用這個基本代碼通過密碼解密它來讀取pdf:
pdfReader = PdfReader(sourceFileInputStream, ReaderProperties().setPassword(ownerPassword.toByteArray()))
但它只適用于我從iText 示例 repo下載的加密 pdf ,它不適用于像這樣的其他 pdf:
- 具有所有者密碼的示例 PDF 1 - ownerpw
- 具有所有者密碼 - ownerpw和用戶密碼 - userpw的示例 PDF 2
它為我提供了上述 pdf 的堆疊跟蹤:
com.itextpdf.kernel.exceptions.BadPasswordException: Bad user password. Password is not provided or wrong password provided. Correct password should be passed to PdfReader constructor with properties. See ReaderProperties#setPassword() method.
at com.itextpdf.kernel.crypto.securityhandler.StandardHandlerUsingAes256.initKeyAndReadDictionary(StandardHandlerUsingAes256.java:253)
at com.itextpdf.kernel.crypto.securityhandler.StandardHandlerUsingAes256.<init>(StandardHandlerUsingAes256.java:89)
at com.itextpdf.kernel.pdf.PdfEncryption.<init>(PdfEncryption.java:245)
at com.itextpdf.kernel.pdf.PdfReader.readDecryptObj(PdfReader.java:1403)
at com.itextpdf.kernel.pdf.PdfReader.readPdf(PdfReader.java:762)
at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1982)
at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:246)
at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:228)
我想我的實作中可能有一些錯誤,所以我嘗試了基于 iText Web 的解鎖器,但它也導致“錯誤的所有者密碼。再試一次。”。
我上面使用的 pdf 是由我生成的,用于使用 Adob??e Acrobat Pro 進行測驗。
這些pdf也被這個在線服務成功解密。
如果有人知道它出了什么問題,請告訴我。謝謝你。
uj5u.com熱心網友回復:
您檔案中的加密資訊無效。
在您檔案的相應加密字典中,R(修訂)值為6,O和U條目的值為 127 位元組長。
但是,根據規范:
| 鑰匙 | 型別 | 價值 |
|---|---|---|
| ○ | 位元組串 | (必需)一個位元組字串,如果R的值為4或更少,則為 32 個位元組長;如果R的值為6 ,則為 48 個位元組長,[...] |
| ü | 位元組串 | (必需)一個位元組字串,如果R的值為4或更少,則為 32 個位元組長;如果R的值為6 ,則為 48 個位元組長,[...] |
(ISO 32000-2,表 21 - 標準安全處理程式的附加加密字典條目)
本質上,48 位元組值附加了零位元組以填充 127 位元組。這是一個已知的 Adob??e Acrobat 錯誤。
請讓 Adob??e 修復他們的軟體。或者請求 iText 支持來解決這個 Adob??e 錯誤。或者自己做后者,iText畢竟是開源的......;)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/521459.html
標籤:pdf文本文本7
