Updated script
This commit is contained in:
parent
7be5c8ee7e
commit
8bb5fef6c7
@ -1,7 +1,10 @@
|
|||||||
# Crypter
|
# Crypter
|
||||||
Script to encrypt and decrypt files easily using openssl
|
Script to encrypt and decrypt files easily using openssl
|
||||||
## Howto
|
## Howto
|
||||||
./crypter.sh [encrypt/decrypt] [inputfile] [outputfile]
|
./crypter.sh -[e/-d] [inputfile]
|
||||||
|
### Options
|
||||||
|
-e for encrypt
|
||||||
|
-d for decrypt
|
||||||
## Additional info
|
## 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.
|
Files are converted using base64 encoding.
|
||||||
|
69
crypter.sh
69
crypter.sh
@ -1,19 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Author: F. Bischof (info@meer-web.nl)
|
# Author: F. Bischof (info@meer-web.nl)
|
||||||
|
KEYS="-des-ede3-cbc -pbkdf2"
|
||||||
# Check method
|
|
||||||
case "$1" in
|
|
||||||
"encrypt")
|
|
||||||
METHOD='encrypt'
|
|
||||||
;;
|
|
||||||
"decrypt")
|
|
||||||
METHOD='decrypt'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: ./crypter.sh [encrypt/decrypt] [inputfile] [outputfile]";
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Check for input file
|
# Check for input file
|
||||||
if [ -n "$2" ]
|
if [ -n "$2" ]
|
||||||
@ -29,56 +16,38 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for output file
|
# Check method
|
||||||
if [ -n "$3" ]
|
case "$1" in
|
||||||
then
|
"-e")
|
||||||
OUTPUT=$3
|
METHOD='encrypt'
|
||||||
if [ -e "$OUTPUT" ];
|
OUTPUT="${INPUT}.crypto"
|
||||||
then
|
;;
|
||||||
echo "Output file already exist!"
|
"-d")
|
||||||
|
METHOD='decrypt'
|
||||||
|
OUTPUT="`echo $INPUT | sed 's/\.crypto//'`"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: ./crypter.sh -[e/d] [inputfile]";
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
else
|
esac
|
||||||
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
|
|
||||||
|
|
||||||
case "$METHOD" in
|
case "$METHOD" in
|
||||||
"encrypt")
|
"encrypt")
|
||||||
echo "Encrypting";
|
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}
|
base64 ${OUTPUT}.temp > ${OUTPUT}
|
||||||
rm -f ${OUTPUT}.temp
|
rm -f ${OUTPUT}.temp
|
||||||
|
rm -f ${INPUT}
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"decrypt")
|
"decrypt")
|
||||||
echo "Decrypting";
|
echo "Decrypting";
|
||||||
base64 -d ${INPUT} > ${INPUT}.temp
|
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 -f ${INPUT}.temp
|
||||||
|
rm -r ${INPUT}
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user