commit
fb85e5f855
@ -1,10 +1,12 @@
|
|||||||
# Crypter
|
# Crypter
|
||||||
Script to encrypt and decrypt files easily using openssl
|
Script to encrypt and decrypt files easily using openssl
|
||||||
## Howto
|
## Howto
|
||||||
./crypter.sh -[e/-d] [inputfile]
|
./crypter.sh -[e/d] [inputfile]
|
||||||
### Options
|
### Options
|
||||||
-e for encrypt
|
-e for encrypt
|
||||||
-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 ~/.crypter/.keys file.\
|
Uses des-ede3-cbc pbkdf2 with salt by default but can be configured in the ~/.crypter/.algos file.\
|
||||||
Files are converted using base64 encoding.
|
Files are converted using base64 encoding.\
|
||||||
|
|
||||||
|
Files hash is checked uppon decrypting
|
||||||
|
34
crypter.sh
34
crypter.sh
@ -16,20 +16,21 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if keys are set
|
# Check if algos are set
|
||||||
if [ ! -f ~/.crypter/.keys ]
|
if [ ! -f ~/.crypter/.algos ]
|
||||||
then
|
then
|
||||||
mkdir -p ~/.crypter
|
mkdir -p ~/.crypter
|
||||||
echo "KEYS=\"-des-ede3-cbc -pbkdf2\"" > ~/.crypter/.keys
|
echo "ALGOS=\"-des-ede3-cbc -pbkdf2\"" > ~/.crypter/.algos
|
||||||
fi
|
fi
|
||||||
source ~/.crypter/.keys
|
source ~/.crypter/.algos
|
||||||
|
|
||||||
# Check method
|
# Check method
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"-e")
|
"-e")
|
||||||
echo "Encrypting file ${INPUT}"
|
echo "Encrypting file ${INPUT}"
|
||||||
OUTPUT="${INPUT}.crypto"
|
HASH=$(sha256sum $INPUT | awk '{ print $1 }')
|
||||||
openssl enc $KEYS -salt -in ${INPUT} -out ${OUTPUT}.temp
|
OUTPUT="${INPUT}.${HASH}.crypto"
|
||||||
|
openssl enc $ALGOS -salt -in ${INPUT} -out ${OUTPUT}.temp
|
||||||
base64 ${OUTPUT}.temp > ${OUTPUT}
|
base64 ${OUTPUT}.temp > ${OUTPUT}
|
||||||
rm -f ${OUTPUT}.temp
|
rm -f ${OUTPUT}.temp
|
||||||
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
|
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
|
||||||
@ -47,18 +48,31 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
"-d")
|
"-d")
|
||||||
echo "Decrypting file ${INPUT}";
|
echo "Decrypting file ${INPUT}";
|
||||||
OUTPUT="`echo $INPUT | sed 's/\.crypto//'`" #Tim of the last extension in future update"
|
OUTPUT=$(echo $INPUT | sed 's/\.crypto//')
|
||||||
|
HASH=$(echo $OUTPUT | sed 's/^.*\.//')
|
||||||
base64 -d ${INPUT} > ${INPUT}.temp
|
base64 -d ${INPUT} > ${INPUT}.temp
|
||||||
openssl enc -d $KEYS -in ${INPUT}.temp -out ${OUTPUT}
|
openssl enc -d $ALGOS -in ${INPUT}.temp -out ${OUTPUT}
|
||||||
rm -f ${INPUT}.temp
|
rm -f ${INPUT}.temp
|
||||||
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
|
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
|
||||||
then
|
then
|
||||||
|
# SHA256SUM CHECK
|
||||||
|
CUR_HASH=$(sha256sum ${OUTPUT} | awk '{ print $1 }')
|
||||||
|
if [ "${HASH}" != "${CUR_HASH}" ]
|
||||||
|
then
|
||||||
|
# NOK - Hash mismatch
|
||||||
|
echo "CRITICAL - Hashes mismatching!"
|
||||||
|
rm -f ${OUTPUT}
|
||||||
|
exit 2
|
||||||
|
else
|
||||||
# OK - safe to delete the original input file
|
# OK - safe to delete the original input file
|
||||||
echo "OK - Deleting file ${INPUT}"
|
echo "OK - Hashes matching, deleting input file"
|
||||||
rm -f ${INPUT}
|
rm -f ${INPUT}
|
||||||
|
mv ${OUTPUT} $(echo $OUTPUT | sed 's/\..*//')
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# NOK - remove empty output file
|
# NOK - remove empty output file
|
||||||
echo "CRITICAL - Output file ${OUTPUT} is 0 bytes! Not removing the source file ${INPUT}"
|
echo "CRITICAL - Output file is 0 bytes! Not removing the input file"
|
||||||
rm -f ${OUTPUT}
|
rm -f ${OUTPUT}
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user