Friday, February 24, 2012

How to encrypt and decrypt a file using openssl

Following command encrypts a file using a passcode
Encrypt
     openssl enc -e -aes-256-cbc -salt -in aman -out aman.ser

Decrypt
     openssl enc -d -aes-256-cbc -salt -in aman -out aman.ser

How to hide password entry in Bourne/bash shell script

Sometimes its required in bash scripts to read a user password. We don't want to echo the password user is entering to the screen. The following shell script accomplishes that

echo -n "Enter password: "
# Save the original stty setting

stty_orig=`stty -g`

# Switch off echoing of password
stty -echo
read password


# Switch things back to normal
stty ${stty_orig}


echo ""
echo "You securely added $password"