home_bin/bash/AESDEC
Doncho Gunchev a84ef39ed8 Add AES encryption/decryption with openssl
The scripts are a bit insecure, safe for home use, see the TODO.
2014-12-16 20:11:12 +08:00

44 lines
888 B
Bash
Executable file

#!/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