openssl_file_encryption/crypter.sh

56 lines
925 B
Bash
Raw Normal View History

2024-02-02 15:49:55 +01:00
#!/bin/bash
2024-02-02 16:02:44 +01:00
# Author: F. Bischof (info@meer-web.nl)
2024-02-21 10:29:45 +01:00
KEYS="-des-ede3-cbc -pbkdf2"
2024-02-02 15:49:55 +01:00
# Check for input file
if [ -n "$2" ]
then
INPUT=$2
if [ ! -e "$INPUT" ];
then
echo "Input file does not exist!"
exit 2
fi
else
echo "Please submit a input file"
exit 1
fi
2024-02-21 10:29:45 +01:00
# Check method
case "$1" in
"-e")
METHOD='encrypt'
OUTPUT="${INPUT}.crypto"
;;
"-d")
METHOD='decrypt'
OUTPUT="`echo $INPUT | sed 's/\.crypto//'`"
;;
*)
echo "Usage: ./crypter.sh -[e/d] [inputfile]";
2024-02-02 15:49:55 +01:00
exit 1
2024-02-21 10:29:45 +01:00
;;
esac
2024-02-02 15:49:55 +01:00
case "$METHOD" in
"encrypt")
echo "Encrypting";
2024-02-21 10:29:45 +01:00
openssl enc $KEYS -salt -in ${INPUT} -out ${OUTPUT}.temp
2024-02-02 15:49:55 +01:00
base64 ${OUTPUT}.temp > ${OUTPUT}
rm -f ${OUTPUT}.temp
2024-02-21 10:29:45 +01:00
rm -f ${INPUT}
2024-02-02 15:49:55 +01:00
echo "Done!"
exit 0
;;
"decrypt")
echo "Decrypting";
base64 -d ${INPUT} > ${INPUT}.temp
2024-02-21 10:29:45 +01:00
openssl enc -d $KEYS -in ${INPUT}.temp -out ${OUTPUT}
2024-02-02 15:49:55 +01:00
rm -f ${INPUT}.temp
2024-02-21 10:29:45 +01:00
rm -r ${INPUT}
2024-02-02 15:49:55 +01:00
echo "Done!"
exit 0
;;
esac
exit 3