NEW: bash script to encrypt/decrypt files

This commit is contained in:
xpk 2024-03-18 16:11:27 +08:00
parent 0c956bc418
commit fb1568da27
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
1 changed files with 28 additions and 0 deletions

28
sh/bash-enc.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
# This script encrypts / decrypts input files with a hard-coded password
export key=53D2714A752F498ED0D0AA52149BB2B624F1C35F4A7997F54ECC83DE60567F7D
export iv=6B22E0637484D90F5EA38C6E4259171F
if [[ $# -lt 2 ]]; then
echo "Usage: bash-enc.sh [-e|-d] input files"
exit 0
fi
OPER=$1
shift
while [[ $# -gt 0 ]];
do
case "$OPER" in
"-e")
openssl enc -aes-256-cbc -e -in $1 -out /dev/shm/$1 -K $key -iv $iv -base64
cat /dev/shm/$1 > $1
shift
;;
"-d")
openssl enc -aes-256-cbc -d -in $1 -out /dev/shm/$1 -K $key -iv $iv -base64
cat /dev/shm/$1 > $1
shift
;;
esac
done