Quickly encrypt a file with OpenSSL
May 2nd, 2007 - Command Line, Mac OS X, Security, Tips & Tricks
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 DZone snippet, but slightly modified and annotated to better accommodate for Mac OS X users:
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.
Encrypt the file:
openssl des3 -salt -in file.txt -out encryptedfile.txt
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.
Source: DZone Snippet – Thanks Jim!
Posted by: David Mendez

Order Mac OS X 10.6 Snow Leopard today from Amazon.com - $25!

Write a comment