[Tex/LaTex] Is it possible to embed (attach) a file password protected in a PDF

attachfiledrmembeddingpdf

The situation is the following, for certain short latex files, I embed the source in the PDF it self. That can save me time in an emergency if I need to modify the source of a PDF without having to look for the original source (which can be in a different computer far away). This is no rocket science, I simply do:

\documentclass{article}
\usepackage{embedfile}
\embedfile{myself.tex}

However in certain situations I don't want other people that have the PDF to look at the Latex source, (for example because of all the comments. Think of a CV)

Of course I can encrypt the embedded file

zip myself.zip --encrypt myself.tex

and use

\embedfile{myself.zip}

(note: in reality I have to change the extension .zip to something else because Acrobat refuses to open embedded zip files)

But then I have to run the external command each time (and also suffer from the interactive zip password input).

Something like this would be ideal if exists but I am open to other possibilities:

\embedfile[password=aaa]{myself.tex} %not working code

I don't want the ultimate security but only a layer of hiding of the embedded file.

This can be also useful for embedding other related material, like original graphics or original data tables, etc. not just tex sources.

Best Answer

It seems that there is not such thing as native encryption (binary or text) of files from TeX. An option would be to issue a command before compilation or a shell command in order to encrypt the file before it is embedded. Doing a little further research I found that there are indeed ways to specify the password non interactively

 \documentclass[]{article}
 \usepackage{embedfile}
 \immediate\write18{zip -j -e -P mypassword -r \jobname.tex.zeep \jobname.tex}
 \embedfile{\jobname.tex.zeep}
 \begin{document}
 bla
 \end{document}

or

 $ zip -j -e -P mypassword -r $0.zeep $0
 $ pdflatex -shell-escape $0

zip can also be replaced by openssl des3 -salt -pass pass:mypassword -in $0 -out $0.de3;

zip is nicer because it opens from the PDF reader using just a double click on the attachments. I also use the extension zeep to avoid stupid email filters.

This is not extremely secure because the password will be visible (still not for the person receiving only the PDF), hopefully it will be a simple passphrase easy to remember at any point.

Thanks Paulo for the inspiration.