Skip to content

Instantly share code, notes, and snippets.

@cmivxx
Created September 29, 2015 22:54
Show Gist options
  • Select an option

  • Save cmivxx/3fab5e8782d52322cdff to your computer and use it in GitHub Desktop.

Select an option

Save cmivxx/3fab5e8782d52322cdff to your computer and use it in GitHub Desktop.
Simple shell script for OSX to encrypt and decrypt files easily.
#!/bin/bash
#############################################################
# OpenSSL Encryption script written by:
# Chris Miller
# chris@intellagentbenefits.com
usage(){
echo "$(tput bold)Usage:$(tput sgr0) $0 enc file_name.txt"
echo "$(tput bold)Usage:$(tput sgr0) $0 unenc file_name.txt"
}
#############################################################
# Show usage instructions
# call usage() function if flag/argument not supplied
# [[ $# -eq 0 ]] && usage
if [[ $1 = "enc" ]]
then
echo "encrypting..."
openssl enc -aes-256-cbc -a -in $PWD/$2 -out $PWD/$2.enc
echo "encrypted"
elif [[ $1 = "unenc" ]]
then
echo "unencrypting..."
openssl enc -d -aes-256-cbc -a -in $PWD/$2 -out $PWD/$2.txt
##############################################################
# Show Help and Usage Instructions
elif [[ $1 = "help" && $2 = "" ]]
then
usage
elif [[ $1 = "" && $2 = "" ]]
then
usage
##############################################################
# Show Bad Command Error & Usage Instructions
else
echo "$1 $2: Bad Command"
echo " "
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment