Sunday, 29 November 2015

Encrypt files with Ruby and OpenSSL

I created this script to make my life easier encrypting files. Google drive, drop box or any other cloud platform don't have an option to password protect or encrypt your files. With this ruby script you will be able to encrypt individual files with a password. It encrypts one file at a time, but if you want a bunch of them you can zip them and encrypt the zip file.
Note: It doesn't use the OpenSSL ruby library, it requires OpenSSL to be installed on your system, it comes by default on Linux, hasn't be tested on Windows

Here's how it works:

Let's say we have the text file below that we want to encrypt.

To Encrypt:

We simply run the ruby script first

Type 1 to encrypt

Type the file name, if the file is under different folder you can type the full path, e.g. /opt/testing/test.txt

Enter a password, (it won't be visible as you type it), and then re enter it.

And that's it, it will create a file under the same path with the extension .des3

To Decrypt:

It's the same process as the encryption, you just need to select option 2 and the file name will have to include the .des3. The output name will be the same excluding .des3, so make sure a file with the same name doesn't exist in that path.