pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastian Gurin <sgu...@softpoint.org>
Subject decrypting documents
Date Mon, 16 Jan 2012 13:43:20 GMT
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)

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);
        decryptionMaterial = new StandardDecryptionMaterial(password);
    AccessPermission ap = document.getCurrentAccessPermission();

<------ here - ap.isOwnerPermission() IS ALWAYS FALSE

        document.save( outfile );
        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. 

Sebastian Gurin <sgurin@softpoint.org>

View raw message