From 8bb5fef6c79437f2043710d98c7674f216efb068 Mon Sep 17 00:00:00 2001 From: Frank Bischof Date: Wed, 21 Feb 2024 10:29:45 +0100 Subject: [PATCH] Updated script --- README.md | 7 ++++-- crypter.sh | 69 +++++++++++++++--------------------------------------- 2 files changed, 24 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index f082ee2..b79e12b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/crypter.sh b/crypter.sh index 035fd2d..9a1e023 100755 --- a/crypter.sh +++ b/crypter.sh @@ -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 ;;