Skip to content

Instantly share code, notes, and snippets.

@shouya
Last active August 21, 2017 05:35
Show Gist options
  • Save shouya/1e3b53436ef2740051757d412257fc31 to your computer and use it in GitHub Desktop.
Save shouya/1e3b53436ef2740051757d412257fc31 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" != 1 -a "$#" != 2 ]; then
echo Usage:
echo 🔒: $0 "<file>"
echo 🔓: $0 "<file>" "<password>"
fi
if [ "$#" = 1 ]; then
file="$1"
base=$(basename "$1")
password=$(openssl rand -hex 7)
openssl enc -aes-256-cbc -in "$file" -out "$file.encrypted" -k "$password"
echo Encrypted file saved to "$file.encrypted"
echo Decrypt with:
echo '$' openssl enc -d -aes-256-cbc -in "$base.encrypted" -out "$base" -k "$password"
echo or:
echo '$' $(basename $0) "$base.encrypted" "$password"
elif [ "$#" = 2 ]; then
file="$1"
dec_file="${1%.encrypted}"
password="$2"
openssl enc -d -aes-256-cbc -in "$file" -out "$dec_file" -k "$password"
echo Decrypted file saved to "$dec_file"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment