Find your content:

Search form

You are here

Encrypt Decrypt the file using sh script

 
Share

Following script might help.

 #!/bin/bash
decrypt=credentials.txt
encrypt=${decrypt}.encrypted

if [[ $# -eq 0 ]] ; then 
    echo "Gimme username"
    read username
    echo "Gimme password"
    read -s password
    echo ${username}:${password} | openssl des3 -salt  -out $encrypt
    echo "File encrypted into $encrypt"
elif [[ $1 = '-d' ]] ; then
    openssl des3 -d -salt -in $encrypt -out $decrypt
    echo "File decrypted into $decrypt"
else 
    echo "Argument $1 not recognized. Either run with no argument for encryption or with '-d' for encryption" >&2
    exit 1
fi

My Block Status

My Block Content