Encrypt files using OpenSSL

Updated . Posted . Visible to the public.

Using OpenSSL it's very easy to seriously encrypt files.
Use the script below. Input / Output are self explanatory. Put a long passphrase into PASSWORD_FILENAME. It is the key to decrypt to file again. Paste this into a console and copy it to wherever you need it.

touch /tmp/openssl_encryption_password && chmod 0700 /tmp/openssl_encryption_password && apg -n1 -m 60 > /tmp/openssl_encryption_password

Remember to at least delete the input file afterwards. Better use shred to wipe files on Linux as used in the script below.

#!/bin/sh
PASSWORD_FILENAME=/opt/backup/openssl_encryption_password
INPUT_FILE=/opt/backup/input
OUTPUT_FILE=/opt/backup/output.enc

/usr/bin/openssl enc -aes-256-cbc -salt -in INPUT_FILE -out OUTPUT_FILE -pass file:$PASSWORD_FILENAME
/usr/bin/shred -u INPUT_FILE
Thomas Eisenbarth
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Thomas Eisenbarth to makandra dev (2011-02-18 17:09)