Updated
This commit is contained in:
parent
8bb5fef6c7
commit
b5dd1cf1d0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
keys
|
@ -7,4 +7,4 @@ Script to encrypt and decrypt files easily using openssl
|
|||||||
-d for decrypt
|
-d for decrypt
|
||||||
## Additional info
|
## Additional info
|
||||||
Uses des-ede3-cbc pbkdf2 with salt by default but can be configured in the $KEY variable.\
|
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.
|
63
crypter.sh
63
crypter.sh
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user