If you don't know the password then obviously you can't decrypt the file... That's the point of the security policy that was applied to it.
On Tue, Sep 29, 2015 at 5:58 PM, Rodney Kite <[email protected]> wrote: > No, Where would I get the password? Its a government document. > > From: Andreas Lehmkuehler <[email protected]> > To: [email protected] > Sent: Tuesday, September 29, 2015 11:48 AM > Subject: Re: trouble decrypting pdf when using loadNonSeq > > Hi, > > Am 29.09.2015 um 13:17 schrieb Toel Hartmann: > > Hi, > > > > I am trying to decrypt a pdf from a customer using pdfbox and loadNonSeq: > > Did you ever try to pass the password by using > > loadNonSeq(File file, RandomAccess scratchFile, String password) > > BR > Andreas > > > > > > > In Acrobat the pfd (I could send a private link to the file) is reported > as “Password Security”: > > Security Method: Password Security > > Document Open Password: No > > Permissions Password: Yes > > Printing: High Resolution > > Changing the Document: Not Allowed > > Commenting: Not Allowed > > Form Field Fill-in or Signing: Not Allowed > > Document Assembly: Not Allowed > > Content Copying: Allowed > > Content Accessibility Enabled: Allowed > > Page Extraction: Not Allowed > > Encryption Level: High (128-bit AES) > > > > but when using the code: > > > > File scratchFile = File.createTempFile("m3_", null); > > FileInputStream fis = null; > > PDDocument doc = null; > > try { > > > > RandomAccessFile scratch = new > RandomAccessFile(scratchFile, "rw"); > > fis = new FileInputStream("build/test/file02.pdf"); > > doc = PDDocument.loadNonSeq(fis, scratch); > > if (doc.isEncrypted()) { > > System.out.println("Pdf is encrypted!!!"); > > StandardDecryptionMaterial sdm = new > StandardDecryptionMaterial(THEPASSWORD); > > doc.openProtection(sdm); > > doc.save("build/test/file02_decrypted.pdf"); > > } > > } catch (Exception e) { > > e.printStackTrace(System.err); > > } finally { > > if (doc!=null) doc.close(); > > if (fis!=null) fis.close(); > > scratchFile.delete(); > > } > > > > using pdfbox 1.8.10 on osx running java 1.8.0_31 I got: > > > > > > org.apache.pdfbox.exceptions.WrappedIOException > > at > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:372) > > at > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptStream(SecurityHandler.java:476) > > at > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:434) > > at > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptObject(SecurityHandler.java:404) > > at > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.proceedDecryption(SecurityHandler.java:222) > > at > org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.decryptDocument(StandardSecurityHandler.java:158) > > at > org.apache.pdfbox.pdmodel.PDDocument.openProtection(PDDocument.java:1609) > > ... > > Caused by: javax.crypto.IllegalBlockSizeException: Input length must be > multiple of 16 when decrypting with padded cipher > > at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:913) > > at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824) > > at > com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436) > > at javax.crypto.Cipher.doFinal(Cipher.java:2004) > > at > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:352) > > ... 32 more > > > > > > If I change to doc = PDDocument.load(fis); > > similar to the code found in Decrypt.java then it is working fine. > > > > > > /Toël > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > > >

