This commit is contained in:
Frank Bischof 2024-02-21 11:29:21 +01:00
parent 8bb5fef6c7
commit b5dd1cf1d0
3 changed files with 39 additions and 27 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
keys

View File

@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
# Author: F. Bischof (info@meer-web.nl) # Author: F. Bischof (info@meer-web.nl)
KEYS="-des-ede3-cbc -pbkdf2"
# Check for input file # Check for input file
if [ -n "$2" ] if [ -n "$2" ]
@ -12,44 +11,56 @@ then
exit 2 exit 2
fi fi
else else
echo "Please submit a input file" echo "Usage: ./crypter.sh -[e/d] [inputfile]";
exit 1 exit 1
fi fi
# Check if keys are set
if [ ! -f keys ]; then echo "KEYS=\"-des-ede3-cbc -pbkdf2\"" > keys; fi
source keys
# Check method # Check method
case "$1" in case "$1" in
"-e") "-e")
METHOD='encrypt' echo "Encrypting file ${INPUT}"
OUTPUT="${INPUT}.crypto" OUTPUT="${INPUT}.crypto"
openssl enc $KEYS -salt -in ${INPUT} -out ${OUTPUT}.temp
base64 ${OUTPUT}.temp > ${OUTPUT}
rm -f ${OUTPUT}.temp
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
then
# OK - safe to delete the original input file
rm -f ${INPUT}
exit 0
else
# NOK - remove empty output file
echo "Output file is 0 bytes! Not removing the source file"
rm -f ${OUTPUT}
exit 2
fi
;; ;;
"-d") "-d")
METHOD='decrypt' echo "Decrypting file ${INPUT}";
OUTPUT="`echo $INPUT | sed 's/\.crypto//'`" OUTPUT="`echo $INPUT | sed 's/\.crypto//'`" #Tim of the last extension in future update"
base64 -d ${INPUT} > ${INPUT}.temp
openssl enc -d $KEYS -in ${INPUT}.temp -out ${OUTPUT}
rm -f ${INPUT}.temp
exit
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
then
# OK - safe to delete the original input file
rm -f ${INPUT}
else
# NOK - remove empty output file
echo "Output file is 0 bytes! Not removing the source file"
rm -f ${OUTPUT}
exit 2
fi
exit 0
;; ;;
*) *)
echo "Usage: ./crypter.sh -[e/d] [inputfile]"; echo "Usage: ./crypter.sh -[e/d] [inputfile]";
exit 1 exit 1
;; ;;
esac esac
case "$METHOD" in
"encrypt")
echo "Encrypting";
openssl enc $KEYS -salt -in ${INPUT} -out ${OUTPUT}.temp
base64 ${OUTPUT}.temp > ${OUTPUT}
rm -f ${OUTPUT}.temp
rm -f ${INPUT}
echo "Done!"
exit 0
;;
"decrypt")
echo "Decrypting";
base64 -d ${INPUT} > ${INPUT}.temp
openssl enc -d $KEYS -in ${INPUT}.temp -out ${OUTPUT}
rm -f ${INPUT}.temp
rm -r ${INPUT}
echo "Done!"
exit 0
;;
esac
exit 3 exit 3