Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.29, 3.0.0 PDFBox
-
None
-
Java 17 on both Linux and Windows
Description
I am using PDFbox to test whether a password is correct for a protected PDF before handling it with a different process. This is working for the vast majority of files I receive but from one particular source PDFbox reports an invalid password when the files can be opened without complaint in GUI applications (Adobe Reader et. al.).
These files are created by scanning to PDF on Xerox MFDs and using the MFD's menus to add a password to the document. As luck would have it I have access to the same MFDs in my location and my files created using the same method are correctly read by PDFbox.
The issue can be seen using the command line utilities and the same is seen on v2.0.29 and v3.0.0-beta1 (I am using the 2.0 series in the application):
❯ java -jar pdfbox-app-2.0.29.jar Decrypt -password JUL2023rfi invalid_password.pdf
Exception in thread "main" org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException: Cannot decrypt PDF, the password is incorrect
at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareForDecryption(StandardSecurityHandler.java:284)
at org.apache.pdfbox.pdfparser.COSParser.prepareDecryption(COSParser.java:2992)
at org.apache.pdfbox.pdfparser.COSParser.retrieveTrailer(COSParser.java:285)
at org.apache.pdfbox.pdfparser.PDFParser.initialParse(PDFParser.java:173)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:226)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1110)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1093)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1070)
at org.apache.pdfbox.tools.Decrypt.decrypt(Decrypt.java:143)
at org.apache.pdfbox.tools.Decrypt.main(Decrypt.java:65)
at org.apache.pdfbox.tools.PDFBox.main(PDFBox.java:52)
❯ java -jar pdfbox-app-3.0.0-beta1.jar Decrypt -password JUL2023rfi -i invalid_password.pdf Error decrypting document [InvalidPasswordException]: Cannot decrypt PDF, the password is incorrect
A sample file is attached, the password is JUL2023rfi