Add AES encryption/decryption with openssl

The scripts are a bit insecure, safe for home use, see the TODO.
This commit is contained in:
Doncho Gunchev 2014-12-16 20:11:12 +08:00
parent 20647b0ef8
commit a84ef39ed8
2 changed files with 82 additions and 0 deletions

44
bash/AESDEC Executable file
View file

@ -0,0 +1,44 @@
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 file_to_decrypt.aes [another_file_to_decrypt.aes]*"
exit 1
fi
# TODO, use mktemp and -pass file:/tmp/tempfile to pass the password
read -ersp "Enter password: " P
echo
while [ ! -z "$1" ]; do
INFILE="$1"
OUTFILE="${1%.aes}"
if [ "$INFILE" = "$OUTFILE" ]; then
echo "The input file does not end with .aes"
shift
continue
fi
if [ -e "$OUTFILE" ]; then
echo "$OUTFILE exists, will not overwrite"
shift
continue
fi
if [ ! -f "$INFILE" ]; then
echo "$INFILE does not exist, can not decrypt"
shift
continue
fi
echo "Processing $INFILE..."
if which bar > /dev/null 2>&1; then
bar -dan -if "$INFILE" | openssl enc -d -aes-256-cbc -salt -pass pass:"$P" > "$OUTFILE"
else
echo -n "Please wait..."
openssl enc -d -aes-256-cbc -salt -pass pass:"$P" < "$INFILE" > "$OUTFILE"
echo " done."
fi
shift
done