Encrypt and Decrypt Large Files in Linux

One tool I’ve found really useful and easy to use for encrypting files is called bcrypt. This is an open source project that uses the BlowFish encryption algorithm. All you have to do is enter the file pattern for the files you want to encrypt and a password. Then when you want to decrypt them, you do a similar thing. More details can be found on their web site.

However, one problem I ran into was not being able to encrypt files larger than one gigabyte. So I had to come up with a custom solution. Fortunately, Linux has some built-in commands to break apart files (and bring them back together). After installing bcrypt, you can use the following instructions to encrypt and decrypt large files.

Suppose you put the following script in a file called encryptFiles.

#!/bin/bash
split -b 100000000 $1 $1.split
rm -f $1

bcrypt -c $1.split*

If you the file you wanted to encrypt were called BigFile.zip, you would enter the following at the command line:

encryptFiles BigFile.zip

It would ask for a password, which you would need to enter.

This will break the files into multiple files that are approximately 1 GB in size and that end with .bfe (which stands for Blowfish encryption).

When you want to decrypt them, you would put the following script in a file called decryptFiles.

#!/bin/bash
bcrypt $1.split*.bfe

cat $1* > $1
rm -f $1.split*

Then you would run the script at the command line by entering:

decryptFiles BigFile.zip

It will ask for the same password with which you encrypted the files.

Obviously, make sure you test it on a copy of the file you want to encrypt before you try it on the actual file.

Please let me know if you have any problems (or successes) with this.

3 Responses to “Encrypt and Decrypt Large Files in Linux”

  1. This approach leaves two problems. 1. It renders bcrypt’s feature to overwrite originating file with garbage, after encryption, useless. 2. bcrypt itself does insanely lot of I/O and split/cat’ing files makes things even worse.

  2. Thanks for the comment and feedback. But what do you propose as an alternative?

  3. Do bcrypt -s0 -c $1.split* :) It will decrease disk writes which are anyway pointless.

Leave a Reply