Quickly Encrypt a File with OpenSSL
Want to encrypt a file quickly? You can do so with OpenSSL at the command line.
A few months ago a question was posed to our readers about encrypting or password protecting a text file [How can I password protect a file?]. We got several good responses but one in particular has really stuck with me. A reader named Jim posted in the comments a tip about using OpenSSL that I have used a bunch since then, and I think others will find this useful as well. This tip is repeated from a reader provided snippet, but slightly modified and annotated to better accommodate for Mac OS X users:
Note: For a detailed article on encrypting and decrypting files with OpenSSL, click here otherwise you can follow the quick guide below:
Encrypt a file using OpenSSL via the Command Line
This is a pretty simple way to encrypt a single file so that it is nearly impossible for others to read, and it will require a password to access again. You’ll need to use the OpenSSL technology via the command line for this to work.
Command syntax for encrypting and decrypting with openssl is as follows:
Quickly Encrypt the file:
openssl des3 -salt -in file.txt -out encryptedfile.txt
Quickly Decrypt the file:
openssl des3 -d -salt -in encryptedfile.txt -out normalfile.txt
Be sure to heed this important advice so you don’t overwrite and lose files:
Do not specify the same file as input and output on encryption.. I have noticed weird effects on OS X (it eats the file). Remove the -in * stuff if you want to pipe data into it (e.g. a tarred folder). Omit the -out * stuff if you want it to pipe data out on STDOUT.
When you encrypt the file initially, it will prompt you to set a password to access the file and decrypt it again in the future – do not forget the password because triple DES encryption is incredibly powerful and you’ll likely lose the file’s content forever without the password. No password means you won’t be accessing the file contents!
Source: snippet thanks to Jim!
Know any other handy command line encryption tips? Share with us!