Encrypt Any Files in Linux

I have been trying to encrypt files and folders lately. It is fun but useful. You can encrypt any file which can take several years to decrypt for a hacker. That “Several” is not less. According to recent super computer “K Computer” which is the fastest can calculate 8,200,000,000,000,000 (8.2 quadrillion) calculations per second. Lets see how many seconds would take to decrypt an encrypted file by the way i am showing.
http://fahadahammed.com/wp-content/uploads/2014/08/Encrypt_Any_Files_in_Linux.png

First Step: Openssl

Openssl is a good choice to encrypt any file. There are several key choice which will make it harder to decrypt. Our magical cracking device “K Computer” would take 2.5 trillion years to recover an AES-256 key.

You have to make sure that Openssl is installed.

apt-get install openssl

Let, there is a text file named file.txt which contains some lines. You can easily read that file by cat command.

Create a file by terminal:

touch file.txt

Put this line by nano:

Our magical cracking device would still take 2.5 trillion years to recover an AES-256 key.
nano file.txt

Save it. You can see or read the file by cat command.

cat file.txt

Let’s encrypt.

Encrypt file.txt to file.enc using 256-bit AES in CBC mode

openssl aes-256-cbc -in file.txt -out file.txt.enc

It will create an encrypted version of file.txt. You can delete the original file.txt.

Decrypt binary file.enc

openssl aes-256-cbc -d -in file.txt.enc -out file.txt.dec

There are many cipher like aes-256-cbc.

aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb
aes-256-cbc aes-256-ecb base64 bf
bf-cbc bf-cfb bf-ecb bf-ofb
camellia-128-cbc camellia-128-ecb camellia-192-cbc camellia-192-ecb
camellia-256-cbc camellia-256-ecb cast cast-cbc
cast5-cbc cast5-cfb cast5-ecb cast5-ofb
des des-cbc des-cfb des-ecb
des-ede des-ede-cbc des-ede-cfb des-ede-ofb
des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb
des-ofb des3 desx rc2
rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb
rc2-ecb rc2-ofb rc4 rc4-40
seed seed-cbc seed-cfb seed-ecb
seed-ofb zlib

Second Step: GPG

To encrypt:

gpg -c file.txt

To decrypt:

gpg file.txt.gpg

Folder Encrypt:

To encrypt folder it is better to make it a zip file and then use above encrypting procedure.

zip -r folder.zip the_folder_to_zip

That’s it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.