pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Lehmkuehler <andr...@lehmi.de>
Subject Re: decrypting documents
Date Sun, 05 Feb 2012 16:36:07 GMT
Hi,

Am 16.01.2012 14:43, schrieb Sebastian Gurin:
> Hi all. I'm having troubles trying to decrypt pdf documents, using the Decrypt.java utility.
Don't know if it is a bug or I'm using it wrong.
>
> I'm not an expert in PDF, so this is my use case for reproducing the problem:
>
> 1) create a simple document using open office writer.
> 2) File->export as pdf file
> 3) set empty password to the file
> 4) verify the generated pdf is openable using acrobat reader.
> 5) Decrypt.main(new String[]{"/the/generatedFile.pdf", /the/generatedFile_decrypted.pdf});
> java.io.IOException: Error: You are only allowed to decrypt a document with the owner
password.
> 	at org.apache.pdfbox.Decrypt.decrypt(Decrypt.java:157)
> 	at org.apache.pdfbox.Decrypt.main(Decrypt.java:57)
> 	at org.softpoint.conv.test.pdf.EncriptedPdfTest.test1(EncriptedPdfTest.java:72)
> 	at org.softpoint.conv.test.pdf.EncriptedPdfTest.main(EncriptedPdfTest.java:18)
There are 2 possible reasons for that:

1: you are using the wrong password
2: you don't have full access to the document (see 7.6.3.2 PDF-reference)

> Other use case:
> the same as above but using the password "test". Verify that acrobat only open the document
with "test" passwrod is provided.
> In the last step I use the following java for decrypting:
> Decrypt.main(new String[]{"-password", "test", "/the/generatedFile.pdf", /the/generatedFile_decrypted.pdf});
>
> and the same exception is thrown.
>
> Note: I also checked calling Decrypt utility from command line with same results.
>
> Note: Debugging the java code, I make sure the password is correct but both use cases
"fail" in the same place, at Decrypt.java:
>
> document = PDDocument.load( infile );
>
> if( document.isEncrypted() )
> {
>      DecryptionMaterial decryptionMaterial = null;
>      if( keyStore != null )
>      {
>          KeyStore ks = KeyStore.getInstance("PKCS12");
>          ks.load(new FileInputStream(keyStore), password.toCharArray());
>
>          decryptionMaterial = new PublicKeyDecryptionMaterial(ks, alias, password);
>      }
>      else
>      {
>          decryptionMaterial = new StandardDecryptionMaterial(password);
>      }
>      document.openProtection(decryptionMaterial);
>      AccessPermission ap = document.getCurrentAccessPermission();
>
>
> <------ here - ap.isOwnerPermission() IS ALWAYS FALSE
>
>      if(ap.isOwnerPermission())
>      {
>          document.save( outfile );
>      }
>      else
>      {
>          throw new IOException(
>          "Error: You are only allowed to decrypt a document with the owner password."
);
>      }
> }
>
> Questions, what is the "alias" and the "PKCS12" ?.
>
> In my context I need to unencrypt documents uploaded by users that can be encrypted using
empty passwords. I need to unencrypt the docments so other tools of my application need an
unencrypted document to work with. I suppose decrypting empty-password-documents should be
possible right?
>
> Thanks in advance, any tip is most appreciated.
>
> Regards

BR
Andreas Lehmkühler

Mime
View raw message