[ https://issues.apache.org/jira/browse/PDFBOX-5866?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17872175#comment-17872175 ]
Tilman Hausherr edited comment on PDFBOX-5866 at 8/9/24 4:02 AM: ----------------------------------------------------------------- I tried changing this code {code} cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(getEncryptionKey(), "AES")); {code} to {code} cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Arrays.copyOf(getEncryptionKey(), 32), "AES")); {code} just to see what would happen, and now this happened: {noformat} Error [SecurityHandler] IOException thrown when decrypting object 4 0 obj Error [COSObject] Can't dereference COSObject{4 0 R} java.io.IOException: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptDataAESother(SecurityHandler.java:344) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:230) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptStream(SecurityHandler.java:545) at org.apache.pdfbox.pdfparser.COSParser.parseFileObject(COSParser.java:562) at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:479) at org.apache.pdfbox.pdfparser.COSParser.dereferenceCOSObject(COSParser.java:433) at org.apache.pdfbox.cos.COSObject.getObject(COSObject.java:118) at org.apache.pdfbox.cos.COSDictionary.getDictionaryObject(COSDictionary.java:183) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptDictionary(SecurityHandler.java:605) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:480) at org.apache.pdfbox.pdfparser.COSParser.parseFileObject(COSParser.java:591) at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:479) at org.apache.pdfbox.pdfparser.COSParser.dereferenceCOSObject(COSParser.java:433) at org.apache.pdfbox.cos.COSObject.getObject(COSObject.java:118) at org.apache.pdfbox.cos.COSArray.getObject(COSArray.java:277) at org.apache.pdfbox.pdmodel.PDPageTree.getKids(PDPageTree.java:151) at org.apache.pdfbox.pdmodel.PDPageTree.get(PDPageTree.java:319) at org.apache.pdfbox.pdmodel.PDPageTree.get(PDPageTree.java:263) at org.apache.pdfbox.debugger.ui.DocumentEntry.getPage(DocumentEntry.java:47) at org.apache.pdfbox.debugger.ui.PDFTreeModel.getChild(PDFTreeModel.java:142) at java.desktop/javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeightLayoutCache.java:1463) at java.desktop/javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeightLayoutCache.java:1272) at java.desktop/javax.swing.tree.VariableHeightLayoutCache.rebuild(VariableHeightLayoutCache.java:728) at java.desktop/javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLayoutCache.java:111) at java.desktop/javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:495) at java.desktop/javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3820) at java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:341) at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333) at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:266) at java.desktop/java.awt.Component.firePropertyChange(Component.java:8731) at java.desktop/javax.swing.JTree.setModel(JTree.java:893) at org.apache.pdfbox.debugger.PDFDebugger.initTree(PDFDebugger.java:1520) at org.apache.pdfbox.debugger.PDFDebugger.readPDFFile(PDFDebugger.java:1443) at org.apache.pdfbox.debugger.PDFDebugger.readPDFFile(PDFDebugger.java:1406) at org.apache.pdfbox.debugger.PDFDebugger$5.actionPerformed(PDFDebugger.java:1608) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369) at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1020) at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.menuDragMouseReleased(BasicMenuItemUI.java:1132) at java.desktop/javax.swing.JMenuItem.fireMenuDragMouseReleased(JMenuItem.java:575) at java.desktop/javax.swing.JMenuItem.processMenuDragMouseEvent(JMenuItem.java:472) at java.desktop/javax.swing.JMenuItem.processMouseEvent(JMenuItem.java:417) at java.desktop/javax.swing.MenuSelectionManager.processMouseEvent(MenuSelectionManager.java:342) at java.desktop/javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.eventDispatched(BasicPopupMenuUI.java:903) at java.desktop/java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2194) at java.desktop/java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2086) at java.desktop/java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2042) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4917) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) Caused by: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. at java.base/com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:975) at java.base/com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1056) at java.base/com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) at java.base/com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2083) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptDataAESother(SecurityHandler.java:340) ... 75 more {noformat} was (Author: tilman): I tried changing this code {code} cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(getEncryptionKey(), "AES")); {code} to {code} cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Arrays.copyOf(getEncryptionKey(), 32), "AES")); {code} just to see what would happen, and how this happened: {noformat} Error [SecurityHandler] IOException thrown when decrypting object 4 0 obj Error [COSObject] Can't dereference COSObject{4 0 R} java.io.IOException: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptDataAESother(SecurityHandler.java:344) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:230) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptStream(SecurityHandler.java:545) at org.apache.pdfbox.pdfparser.COSParser.parseFileObject(COSParser.java:562) at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:479) at org.apache.pdfbox.pdfparser.COSParser.dereferenceCOSObject(COSParser.java:433) at org.apache.pdfbox.cos.COSObject.getObject(COSObject.java:118) at org.apache.pdfbox.cos.COSDictionary.getDictionaryObject(COSDictionary.java:183) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptDictionary(SecurityHandler.java:605) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:480) at org.apache.pdfbox.pdfparser.COSParser.parseFileObject(COSParser.java:591) at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:479) at org.apache.pdfbox.pdfparser.COSParser.dereferenceCOSObject(COSParser.java:433) at org.apache.pdfbox.cos.COSObject.getObject(COSObject.java:118) at org.apache.pdfbox.cos.COSArray.getObject(COSArray.java:277) at org.apache.pdfbox.pdmodel.PDPageTree.getKids(PDPageTree.java:151) at org.apache.pdfbox.pdmodel.PDPageTree.get(PDPageTree.java:319) at org.apache.pdfbox.pdmodel.PDPageTree.get(PDPageTree.java:263) at org.apache.pdfbox.debugger.ui.DocumentEntry.getPage(DocumentEntry.java:47) at org.apache.pdfbox.debugger.ui.PDFTreeModel.getChild(PDFTreeModel.java:142) at java.desktop/javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeightLayoutCache.java:1463) at java.desktop/javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeightLayoutCache.java:1272) at java.desktop/javax.swing.tree.VariableHeightLayoutCache.rebuild(VariableHeightLayoutCache.java:728) at java.desktop/javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLayoutCache.java:111) at java.desktop/javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:495) at java.desktop/javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3820) at java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:341) at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333) at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:266) at java.desktop/java.awt.Component.firePropertyChange(Component.java:8731) at java.desktop/javax.swing.JTree.setModel(JTree.java:893) at org.apache.pdfbox.debugger.PDFDebugger.initTree(PDFDebugger.java:1520) at org.apache.pdfbox.debugger.PDFDebugger.readPDFFile(PDFDebugger.java:1443) at org.apache.pdfbox.debugger.PDFDebugger.readPDFFile(PDFDebugger.java:1406) at org.apache.pdfbox.debugger.PDFDebugger$5.actionPerformed(PDFDebugger.java:1608) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369) at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1020) at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.menuDragMouseReleased(BasicMenuItemUI.java:1132) at java.desktop/javax.swing.JMenuItem.fireMenuDragMouseReleased(JMenuItem.java:575) at java.desktop/javax.swing.JMenuItem.processMenuDragMouseEvent(JMenuItem.java:472) at java.desktop/javax.swing.JMenuItem.processMouseEvent(JMenuItem.java:417) at java.desktop/javax.swing.MenuSelectionManager.processMouseEvent(MenuSelectionManager.java:342) at java.desktop/javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.eventDispatched(BasicPopupMenuUI.java:903) at java.desktop/java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2194) at java.desktop/java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2086) at java.desktop/java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2042) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4917) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) Caused by: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. at java.base/com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:975) at java.base/com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1056) at java.base/com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) at java.base/com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2083) at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptDataAESother(SecurityHandler.java:340) ... 75 more {noformat} > Unable to load password protected pdf > -------------------------------------- > > Key: PDFBOX-5866 > URL: https://issues.apache.org/jira/browse/PDFBOX-5866 > Project: PDFBox > Issue Type: Bug > Reporter: Charles D > Priority: Major > Attachments: pdfbox_invalid_pwd.pdf > > > PDFBox is unable to load password protected pdf. Error is "Invalid AES key > length: 48 bytes." > Adobe and qpdf are able to successfully open it , but many other applications > I've tried are unable to do so. > The pdf is created by a third party scanner so unfortunately we have no > insight/control over its creation. > [^pdfbox_invalid_pwd.pdf] . Please let me know the best way to provide the > password. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org