Code, Computers & Random Junk

Encrypting Files With OpenSSL

I saw a terminal command to encrypt/decrypt files really easy in Terminal. So, I thought I should do a script of it. It’s nothing fancy or so - just a wrapper to make it (even) easier to use.

The encryption/decryption it self looks like this:


# blowfish
openssl enc -bf -A -in "/path/to/file.txt" > "/path/to/"

# aes256
openssl enc -aes256 -A -in "/path/to/file.txt" > "/path/to/file.txt.aes"


# blowfish
openssl enc -bf -A -d -in "/path/to/" > "/path/to/file.txt"

# aes256
openssl enc -aes256 -A -d -in "/path/to/file.txt.aes" > "/path/to/file.txt"

It’s more|less about adding a -d to the decryption, and reverse the file order.

The script I made (encFile) will simplify it, and one doesn’t need to remember the options or order. I simply use:

encFile /path/to/file.txt

That will produce the file: /path/to/ I’ve set Blowfish to default, but it’s easy to specify with:

encFile bf /path/to/file.txt
encFile aes /path/to/file.txt

To decrypt… Just run the file. The script will decrypt using bf (blowfish) or aes256 based on the file extension.

encFile /path/to/
encFile /path/to/file.txt.aes

Here’s the script:

Happy hacking…