1

I'd like to open an encrypted pdf document without saving its decrypted content to my disk/ramdisk using a standard document viewer.

I already tried something like

gpg --decrypt foo.pdf.gpg | evince /dev/stdin

But this doesn't work.

Anything helps!

  • Whatever you do there will be always the possibility that the system swaps on the swap partition when you use evince with the encrypted pdf... and for what it concerns the ram (not the ramdisk), somewhere the data and somewhere else the image (created by evince) have to be stored... – Hastur Nov 3 '15 at 11:42
  • That's not my problem. I just don't want to decrypt it and forget to delete it. I'm aware of all side effects. I'm just searching for a convenient one-liner without having an additional file. – rralf Nov 3 '15 at 11:49
1

Reading your comment I think you can create a temporary file and destroy it as you exit from evince.

gpg --output bar.$$.pdf --decrypt foo.pdf.gpg ; evince bar.$$.pdf ; rm bar.$$.pdf

(Note with $$ you take the PID of the current BASH session).

If you want to increase the security you can create a little script that executes the above commands and wait the end of evince in a subshell (). You can start with something like the below one... chmod u+x foobar.sh to make it executable.

#!/bin/bash

FileToDecript=${1}                 # pass the name as 1st parameter
[ $# != 1 ] && exit 1;             # exit if you forget about it
FileOut="temp.$$.pdf"              # temporary filename with the bash PID
gpg --output $FileOut --decrypt $FileToDecript ;
[ ! $? -eq 0 ] && exit 2;          # exit if failed to decrypt

                                   # The following run in a subshell (...)
( evince $FileOut  &                  # evince runs in background
  wait $!                             # here wait evince ends
  rm $FileOut ) &                     # here remove the file
                                   # the subshell is executed in background `&`

You may want to create the temp file in special directory that cannot be read by other users and maybe under the /tmp or another one that will be erased on the next reboot.

  • +1 for the idea. Let me think a day about this approach. Actually I would prefer a one-liner without any additional file, but this is okay. What about saving the temp file using mktemp? – rralf Nov 3 '15 at 13:39
  • The one line command works (it is the first written) but it hangs the terminal... but it's fixable (gpg --output bar.$$.pdf --decrypt foo.pdf.gpg ; evince bar.$$.pdf ; rm bar.$$.pdf) &. I give the script because you can modify more easily adding maybe chmod a-r tempfile; chmod u+r tempfile, personal "temp" directory, hidden buried and protected etc etc... You can even write a bash function to open the file in a temporary directory. mktemp will create a file that usually the other users can read... that conflicts with the concept of using GPG... – Hastur Nov 3 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.