Skip to content

Instantly share code, notes, and snippets.

@s7ephen
Created October 11, 2017 04:43
Show Gist options
  • Save s7ephen/23bab58dff8ac90a906a2216b8636285 to your computer and use it in GitHub Desktop.
Save s7ephen/23bab58dff8ac90a906a2216b8636285 to your computer and use it in GitHub Desktop.
Use the openssl binary/version on OSX to do symmetric crypto.
#!/bin/bash
# Use the openssl binary/version on OSX to do symmetric crypto.
# stephen@senr.io
if [ "$#" != "2" ]
then
echo "Usage: ghettocrypt.sh encrypt file_to_encrypt.zip" 1>&2
echo " OR" 1>&2
echo "ghettocrypt.sh decrypt file_to_decrypt.zip.enc" 1>&2
exit 1
fi
function die {
echo "Something is fucked up. I can't help you. I give up" 1>&2
exit 1
}
action=$1
crypt_file=$2
# attempt to do the crypto
if [ "${action}" == "encrypt" ]
then
echo "Please enter your password, then hit Enter: " 1>&2
openssl aes-256-cbc -in "${crypt_file}" -out "${crypt_file}.enc" -pass stdin || die
echo "Your encrypted file written to ${crypt_file}.enc"
fi
if [ "${action}" == "decrypt" ]
then
echo "Please enter your password, then hit Enter: " 1>&2
openssl aes-256-cbc -d -in "${crypt_file}" -out "${crypt_file}.decrypted" -pass stdin || die
echo "Your decrypted file written to ${crypt_file}.decrypted"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment