OpenSSL Encryption Fun

I re-discovered the fun that is OpenSSL’s encryption today when I was cleaning up some bash aliases and though I’d share them.

This allows you to do some really stupid but fun things like encrypt backups, or messages to pass to a buddy. The uses are endless!

# Put this somehwere in .bashrc/aliases/etc.
# OpenSSL must be installed -- these are just aliases.
alias enc='openssl enc -e -aes-256-cbc -salt '
alias dec='openssl enc -d -aes-256-cbc '
# encrypted gzipped db dump
mysqldump -uroot DBNAME|enc|gzip -c>db.sql.enc.gz

# decrypted gzipped db dump
gunzip -dc db.sql.enc.gz|dec>db.sql

# decrypted gzipped db dump to import -- sneaky sneaky o_O
gunzip -dc db.sql.enc.gz|dec|mysql -uroot DBNAME

# encrypted tarball
tar czf - blah/|enc > blah.tar.gz.enc

# decrypt encrypted tarball
dec < blah.tar.gz.enc|tar xzf - 

# fun with passwords!
enc < passwords.txt > passwords.txt.enc
dec < passwords.txt.enc > passwords.txt

# ... and so on and so forth ...

View Gist