Friday, December 23, 2011

Encrypting and decrypting files using openssl

Creating simple backups I felt, the backup shall not stay in form of plain zip archive, not even encrypted one (as they easily reveal file names, which are stored in the archive), so I searched for options to get a file and encrypt it.

OpenSSH project is offering such a tool, and it can be run from command line on Windows as well as on Linux.

On Linux is the openssl command already available, on Windows it must be installed. I found, that I got it installed together with OpenVPN, and it is located in the bin directory of OpenVPN.
You can also follow instructions from OpenSSL web page and choose one of the options on this web page:


Assuming, you have a file readme.txt and want to encrypt it:

$ openssl enc -e -aes256 -in readme.txt -out readme.txt.aes256

When you run this command, you will be prompted to enter a password (choose strong one) twice and finally a file readme.txt.aes256 is created.

To decrypt the file:

$ openssl enc -d -aes256 -in readme.txt.aes256 -out readme.txt.decrypted

You will be asked to enter a password and file readme.txt.decrypted will be created.


There are far more options, but the one above shall be sufficient.


There are numerous encryption algorithms available, and I recommend you  just to stick with one and do enter the name of the algorithm in file extension. Otherwise you will have to remember what method you really used (openssl does not detect the method used, you have to enter it).

For more see http://prefetch.net/articles/realworldssl.html

No comments:

Post a Comment