*NIX Tricks

[security] Encrypt a PDF file in the command line

Posted in security by kousik on December 16, 2011

There are a few command line tools to encrypt/ password-protect a file, for example OpenSSL, GnuPG. However, if you want to send someone an encrypted PDF who does not have access to these CLI tools, then that’s not cool for the recipient at all! Pdftk is another open-source command line tool that can encrypt a PDF file which can be decrypted using either Pdftk in the commandline or entering the password in a GUI pop-up box when the recipient tries to open the PDF file using a PDF viewer (for example, Adobe Reader).

Examples (taken from PDF Labs):

1. Encrypt a PDF using 128-Bit Strength (the Default) and Withhold All Permissions (the Default)

$ pdftk mydoc.pdf output mydoc.128.pdf owner_pw foopass

2. Same as Above, Except a Password is Required to Open the PDF

$ pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz

3. Same as Above, Except Printing is Allowed (after the PDF is Open)

$ pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz allow printing

4. Decrypt a PDF

$ pdftk secured.pdf input_pw foopass output unsecured.pdf


NOTE:
Setting an owner password prevents the document from being modified unless the password is provided. In the same way, setting a user password prevents the user to view the file.

Advertisement
Tagged with: , , , , ,

One Response

Subscribe to comments with RSS.

  1. sahil khanna said, on January 4, 2012 at 2:23 AM

    hi, just dropped by to say i have nominated you for the 7×7 link award http://sahilkhanna.wordpress.com/2012/01/04/7×7-award/ grab it here :)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.