Last active
February 18, 2023 05:17
-
-
Save carlos-a-g-h/6e3d805c20a918562922d34e19c2c0d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Enctool is a script for encrypting or decrypting a group of specific files using openssl | |
# Usage | |
# $ enctool.sh {ACTION} {PASSWORD} | |
# Requires a file in CSV format called "enctool.csv" among the target files | |
# For each row: the first column is the original filename and the second column is the encrypted filename | |
# The columns must be separated by a tab character | |
ACTION="$1" | |
PASSWD="$2" | |
CSV="enctool.csv" | |
CSV_LINES=$(cat $CSV|wc -l) | |
INDEX=0 | |
while [ $INDEX -lt $CSV_LINES ] | |
do | |
LN=$((INDEX + 1)) | |
PAIR="$(cat $CSV|head -n $LN|tail -n 1)" | |
OFILE=$(printf "$PAIR"|cut -f 1) | |
EFILE=$(printf "$PAIR"|cut -f 2) | |
echo "- orig: $OFILE" | |
echo " encr: $EFILE" | |
if [[ "$ACTION" == "enc" ]] | |
then | |
if [ -e "$OFILE" ] | |
then | |
openssl enc -aes-256-cbc -e -in "$OFILE" -out "$EFILE" -k "$PASSWD" -pbkdf2 | |
if [ $? -eq 0 ] | |
then | |
rm "$OFILE" | |
fi | |
fi | |
fi | |
if [[ "$ACTION" == "dec" ]] | |
then | |
if [ -e "$EFILE" ] | |
then | |
openssl enc -aes-256-cbc -d -in "$EFILE" -out "$OFILE" -k "$PASSWD" -pbkdf2 | |
if [ $? -eq 0 ] | |
then | |
rm "$EFILE" | |
fi | |
fi | |
fi | |
INDEX=$((INDEX + 1)) | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This variant of enctool uses a simple filename listing, rather than a CSV, but it does the same job | |
# Usage | |
# $ enctool.sh {PREFIX} {ACTION} {PASSWORD} | |
# PREFIX = name of the list or group of files | |
# ACTION = Encrypt (enc) / Decrypt (dec) | |
# PASSWORD = Password for encrypting or decrypting | |
# Required file: "enctool.PREFIX.lst" | |
# PREFIX = custom filename prefix for the encrypted files | |
# The contents of the file is a simple list of filenames | |
PREFIX="$1" | |
ACTION="$2" | |
PASSWD="$3" | |
LST="enctool.""$PREFIX"".lst" | |
LST_LINES=$(cat $LST|wc -l) | |
INDEX=0 | |
while [ $INDEX -lt $LST_LINES ] | |
do | |
LN=$((INDEX + 1)) | |
OFILE="$(cat $LST|head -n $LN|tail -n 1)" | |
EFILE="$PREFIX"".""$LN"".bin" | |
echo "- orig: $OFILE" | |
echo " encr: $EFILE" | |
if [[ "$ACTION" == "enc" ]] | |
then | |
if [ -e "$OFILE" ] | |
then | |
openssl enc -aes-256-cbc -e -in "$OFILE" -out "$EFILE" -k "$PASSWD" -pbkdf2 | |
if [ $? -eq 0 ] | |
then | |
rm "$OFILE" | |
fi | |
fi | |
fi | |
if [[ "$ACTION" == "dec" ]] | |
then | |
if [ -e "$EFILE" ] | |
then | |
openssl enc -aes-256-cbc -d -in "$EFILE" -out "$OFILE" -k "$PASSWD" -pbkdf2 | |
if [ $? -eq 0 ] | |
then | |
rm "$EFILE" | |
fi | |
fi | |
fi | |
INDEX=$((INDEX + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment