site Search:


 
   
story category
Encrypt files quickly with OpenSSL
Stupid Terminal Tricks
by rjackson Saturday 15-Sep-2007
A co-worker pointed out to me that OpenSSL can be used on the command line to encrypt and decrypt files quickly and easily.

Observe:
openssl enc -aes-256-cbc -e -in note.txt -out note.txt.enc -pass pass:money
 
That will take the file note.txt and create an encrypted version called note.txt.enc, encrypted aes 128 with the password "money".

And to decrypt it back to plaintext:
openssl enc -aes-256-cbc -d -in note.txt.enc -out note.txt -pass pass:money
 

In fact, he even wrote a quick-and-dirty shell script, which I will distribute here.
#!/bin/bash
####################################################
# Lazy Crypto
# Written By: Captain Bossman
# 
# Eases the pain of encrypting and decrypting 
# individual files using OpenSSL.  
#
# Please do not be alarmed that this is a quick and
# dirty hack.  Feel free to use this for anything
# if you happen to find it useful. 
# 
# Please direct any support requests to 
# http://www.google.com
####################################################

# Encryption algorhythm to use. 
# Check 'openssl enc help' for options. 

algo="aes-256-cbc" 

# Panic if we don't have the right number of 
# arguments 
if [ "$2" == "" ]; then 
	
	    echo "Usage: $0 [ encrypt|decrypt ] filename"
	    exit 2 
else
 
    	    echo -n "Passphrase: " 
	    stty -echo   
	    read passwd
	    stty echo
	    echo

case "$1" in 
	encrypt)
	    openssl enc -$algo -e -in $2 -out $2.enc -pass pass:$passwd; 
	;;
	decrypt)
	    openssl enc -$algo -d -in $2 -out `echo $2 | sed -e 's/\.enc//'` -pass pass:$passwd;
	;;

	*)
	    echo "Usage: $0 [ encrypt|decrypt ] filename";
	;;
esac
fi
 
Usage is simple, I have it saved as lcr.sh in /usr/local/bin. Just type lcr.sh encrypt filename and then enter a password when prompted. And then use lcr.sh decrypt filename.enc to convert it back.

home

Burn Folder

the best blog by rjackson on dslr
comments?




Monday, 04-Jun 16:55:21 Terms of Use & Privacy | feedback | contact | Hosting by nac.net - DSL,Hosting & Co-lo
over 12.5 years online © 1999-2012 dslreports.com.