Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Ease encrypt/decrypt via ssl with two functions UNIX
The following two functions (just add to your .bash_profile or .profile file) will make life easier when encrypting and decrypting files with openssl in Terminal:
function encrypt {
  if [ "$1" = "" ]; then
    echo "Usage: encrypt filename"
  elif [ -d "$1" ]; then
    echo ""$1" is a directory"
  elif [ -L "$1" ]; then
    echo ""$1" is a symbolic link"
  elif ! [ -r "$1" ]; then
    echo ""$1" is not readable"
  else
    /usr/bin/openssl aes-256-cbc -salt -in "$1" -out "$1".aes
      if [ $? -eq 0 ] ; then
        echo "encryted file: "$1".aes"
      fi
  fi
}

function decrypt {
  if [ "$1" = "" ] || [ "${1##*.}" != aes ]; then
    echo "Usage: decrypt filename.aes"
  else
    /usr/bin/openssl aes-256-cbc -d -salt -in "$1" -out "${1%.aes}" 2>/dev/null
      if [ $? -eq 0 ] ; then
        echo "decryted file: ${1%.aes}"
      else
        /bin/rm "${1%.aes}"
        echo -e "bad decrypt, possible incorrect password \n(${1%.aes} deleted)"
      fi
  fi
}
[robg adds: I haven't tested these functions.]
    •    
  • Currently 2.75 / 5
  You rated: 4 / 5 (12 votes cast)
 
[6,093 views]  

Ease encrypt/decrypt via ssl with two functions | 1 comments | Create New Account
Click here to return to the 'Ease encrypt/decrypt via ssl with two functions' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Ease encrypt/decrypt via ssl with two functions
Authored by: wreleven on Oct 15, '09 10:42:30AM

If it's a directory then you could .zip or .gz it and then encrypt the resulting file? On decrypt you'd just then unzip the file after decrypting.



[ Reply to This | # ]