ruby-on-railspdfpdf-generationprawn

Prawn PDF Encryption Bit Increase


I used Prawn to generate PDF's in Rails and I noted that in the documentation from line 76 that:

The encryption used is weak; the key is password-derived and islimited to 40 bits, due to US export controls in effect at the time the PDF standard was written. There is nothing technologically requiring PDF readers to respect the permissions embedded in a document. Many PDF readers do not. In short, you have no security at all against a moderately motivated person. Don't use this for anything super-serious. This is not a limitation of Prawn, but is rather a built-in limitation of the PDF format.

I understand you can easily get around the encryption, but the law in my country requires 128 bit encryption. Is there a way to increase it in Prawn PDF?


Solution

  • As mentioned in one of the comments, you could use HexaPDF instead of Prawn for generating your documents and use AES 128bit or 256bit encryption. This, however, would mean you need to completely revamp your code as the document creation facilities are a bit different.

    What would be easier for you is to post-process your Prawn generated PDF document to encrypt it in a second step. I.e. first create the document using Prawn without encryption and then apply the encryption afterwards.

    The second step could be done using HexaPDF directly after generating the PDF document with Prawn, inside the same Ruby process. Or you can use any of the CLI tools that allow this, like hexapdf (the CLI companion of the HexaPDF library), qpdf, pdftk...

    [N.b. I'm the author of HexaPDF.]