Updated script

This commit is contained in:
Frank Bischof 2024-02-21 10:29:45 +01:00
parent 7be5c8ee7e
commit 8bb5fef6c7
2 changed files with 24 additions and 52 deletions

View File

@ -1,7 +1,10 @@
# Crypter
Script to encrypt and decrypt files easily using openssl
## Howto
./crypter.sh [encrypt/decrypt] [inputfile] [outputfile]
./crypter.sh -[e/-d] [inputfile]
### Options
-e for encrypt
-d for decrypt
## Additional info
Uses des-ede3-cbc pbkdf2 with salt.\
Uses des-ede3-cbc pbkdf2 with salt by default but can be configured in the $KEY variable.\
Files are converted using base64 encoding.

View File

@ -1,19 +1,6 @@
#!/bin/bash
# Author: F. Bischof (info@meer-web.nl)
# Check method
case "$1" in
"encrypt")
METHOD='encrypt'
;;
"decrypt")
METHOD='decrypt'
;;
*)
echo "Usage: ./crypter.sh [encrypt/decrypt] [inputfile] [outputfile]";
exit 1
;;
esac
KEYS="-des-ede3-cbc -pbkdf2"
# Check for input file
if [ -n "$2" ]
@ -29,56 +16,38 @@ else
exit 1
fi
# Check for output file
if [ -n "$3" ]
then
OUTPUT=$3
if [ -e "$OUTPUT" ];
then
echo "Output file already exist!"
# 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]";
exit 1
fi
else
echo "Please submit a output file"
exit 1
fi
# Ask for password
echo -en "Encryption password: "
read -s PASSWORD; echo ""
if [ "$PASSWORD" == '' ]
then
echo "Password not set!"
exit 2
fi
if [ "$METHOD" == 'encrypt' ]
then
echo -en "Confirm password: "
read -s PASSWORD_CONFIRM
echo ""
if [ "$PASSWORD" != "$PASSWORD_CONFIRM" ]
then
echo "Passwords are not matching!"
exit 2
fi
fi
;;
esac
case "$METHOD" in
"encrypt")
echo "Encrypting";
openssl enc -des-ede3-cbc -pbkdf2 -salt -in ${INPUT} -out ${OUTPUT}.temp -k ${PASSWORD}
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 -des-ede3-cbc -pbkdf2 -in ${INPUT}.temp -out ${OUTPUT} -k ${PASSWORD}
openssl enc -d $KEYS -in ${INPUT}.temp -out ${OUTPUT}
rm -f ${INPUT}.temp
rm -r ${INPUT}
echo "Done!"
exit 0
;;