java - Apache PDFBox - can't decrypt PDF -
I have a problem decrypting a PDF document with Apache PDF (v1.8.2) I encryption works, but Encryption with one password throws an exception (Java 1.6)
package com.test; Import org.apache.pdfbox.pdmodel.PDDocument; Import org.apache.pdfbox.pdmodel.encryption.AccessPermission; Import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial; Import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; Public class PdfEncDecTest {static string pdfPath = "G: \\ files \\ filed5b3.pdf"; Public final static string PDF_OWNER_PASSWORD = "cd1j"; Public final static string PDF_USER_PASSWORD = ""; Public static void main (String [] args) Exceptions Throws (PDDocument document = PDDocument.load (pdfPath); AccessPermission AP = new Aksespramisn (); ap.setCanPrint (right); ap.setCanExtractContent (false); ap.setCanExtractForAccessibility ( false); standard security policy psp = new standard security policy (PDF_OWNER_PASSWORD, PDF_USER_PASSWORD, AP); document.protect (sPP); document.save (pdfPath + ". pdf"); document.close (); PDDocument document = PDDocument. Load (pdfPath + ".pdf"); if (doc.isEncrypted ()) {standard decryption content SDM = new standard decryption content (PDF_OWNER_PASSWORD); doc.openProtection (S DM); // org.apache.pdfbox.exceptions.CryptographyException: Error: The password supplied with the owner or user password in the mail does not match. Doc.decrypt (PDF_OWNER_PASSWORD); // as above) doc.close (); }} I do not know what's wrong. With version 1.8.7, I get the same exception. I have posted the complete code above
exception in the formula "main" org.apache.pdfbox.exceptions.CryptographyException:. Error: The owner or user does not match the password in the supplied password. In org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareForDecryption (org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.decryptDocument (StandardSecurityHandler.java:156) at) Org.apache.pdfbox.pdmodel (ensure safety standards . .PDDocument.openProtection (PDDocument.java:1595) org.apache.pdfbox.pdmodel.PDDocument.decrypt (PDDocument.java:942) com.test.PdfEncDecTest.main on (PdfEncDecTest.java:29) < On / Pre> I have placed the sample project on the gitub:
You need user password Is
if (doc.isEncrypted ()) {StandardDecryptionMaterial SDM = New StandardDecryptionMaterial (PDF_USER_PASSWORD); doc.openProtection (SDA ); // Do not call decrypt ()}} This works even if the user password is not empty. The user's password encryption is about what the person thinks, the owner password There is an encryption for security rights.
Edit: Sorry, my answer is wrong, although it was helpful, you can open a PDF with a user password (you will probably get restricted rights) or with owner password (you will get full rights ). What could have happened is that the owner has a bug with matching the password to 40 bit keys (which is the default). This bug is currently being investigated, look up and search for "MD5".
Comments
Post a Comment