views:

1050

answers:

4

Is there any way to decrypting a pdf protected by an aes-256 bit key?

I have the correct password and I need a command-line tool (or library - perhaps in python :P ) for decrypting the file and then doing some operation over it.

The best thing could be if the file could be saved decrypted, then I elaborate it and then I can remove it...

Does anyone know something about it?

A: 

Here is a plugin to read encrypted PDFs in GhostScript.

If it works for you, you can use it, or read its source code.

There are other, similar options, i.e. Imagemagick can read encrypted PDFs and convert them to something else, and has python bindings.

nosklo
unfortunately I can't use these things because my pdf file contains a custom stream which will be loose if I convert the file :\
Giancarlo
A: 

The pdftk program runs on the command line and will allow you to decrypt the file and store the decrypted version.

--
bmb

bmb
+1  A: 
import pyPdf                                                                
pdf = pyPdf.PdfFileReader(open("file.pdf"))
pdf.decrypt("password")

You can then do whatever you want with the contents. This will work with either the user or owner passwords.

Tony Meyer
however I can't decrypt pdf files made through adobe acrobat 6 or later
Giancarlo
A: 

Appligent Document Solutions' APCrypt 4.0 will decrypt (and encrypt) 256-bit AES encrypted PDF files.

As you requested, it's a command-line tool.

http://www.appligent.com/apcrypt

Duff Johnson