{"id":1116,"date":"2014-08-19T18:18:41","date_gmt":"2014-08-19T18:18:41","guid":{"rendered":"http:\/\/scunster.co.uk\/?p=1116"},"modified":"2014-08-19T18:20:24","modified_gmt":"2014-08-19T18:20:24","slug":"encrypting-decrypting-files-and-directories-using-openssl","status":"publish","type":"post","link":"https:\/\/scunster.co.uk\/?p=1116","title":{"rendered":"Encrypting &#038; Decrypting files and directories using OpenSSL"},"content":{"rendered":"<p>Encrypt &#038; Decrypt a single file<br \/>\n===============================<br \/>\nTo encrypt the file img1.jpg to the encrypted file ing1.jpg.enc use the following<br \/>\nYou will be promoted to type your encryption password, do not forget it!<\/p>\n<pre>openssl aes-256-cbc -a -salt -in img1.jpg -out img1.jpg.enc<\/pre>\n<p>To decrypt the encrypted file img1.jpg.enc back to img1.jpg type following<br \/>\nYou will be prompted for the decryption password that you set above.<\/p>\n<pre>openssl aes-256-cbc -d -a -in img1.jpg.enc -out img1.jpg<\/pre>\n<p>Encrypt &#038; Decrypt multiple files within one directory<br \/>\n=====================================================<br \/>\nTo encrypt all files in one folder with a password that you set form the command line<\/p>\n<pre>for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done<\/pre>\n<p>To encrypt all files in one folder with a password that you set in the file author.txt and then remove all the original JPG files and the author.txt file itself for obvious reasons!<\/p>\n<pre>for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -pass file:author.txt ; done ; rm *.JPG ; rm *.txt<\/pre>\n<p>To encrypt all files in one folder with a password set in the command line and then erase the bash history and remove all tar files. We remove the bash history so that your password is not retrievable by simply pressing the up arrow key!<\/p>\n<pre>for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done ; rm *.tar ; history -c && history -w<\/pre>\n<p>Encrypt &#038; Decrypt all files recursively from parent directory<br \/>\n=============================================================<br \/>\nEncrypt all files recursively with a password set from the command line and then erase the bash history and remove all the original tar files.<br \/>\nThis assumes that the files to be encrypted are tar files, you can of course run the command on any type of file extension.<\/p>\n<pre>for f in **\/*.tar ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done ; rm **\/*.tar ; history -c && history -w<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Encrypt &#038; Decrypt a single file =============================== To encrypt the file img1.jpg to the encrypted file ing1.jpg.enc use the following You will be promoted to type your encryption password, do not forget it! openssl aes-256-cbc -a -salt -in img1.jpg -out img1.jpg.enc To decrypt the encrypted file img1.jpg.enc back to img1.jpg type following You will be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,171],"tags":[207,208,205,206,203,210,211,204,209],"class_list":["post-1116","post","type-post","status-publish","format-standard","hentry","category-linux","category-security-linux","tag-decrypt","tag-decryption","tag-encrypt","tag-encryption","tag-openssl","tag-recursive","tag-recursively","tag-ssl","tag-tar"],"_links":{"self":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1116"}],"version-history":[{"count":2,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1116\/revisions"}],"predecessor-version":[{"id":1118,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1116\/revisions\/1118"}],"wp:attachment":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}