2024-03-18 16:11:27 +08:00
|
|
|
#!/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")
|
2024-03-18 16:19:35 +08:00
|
|
|
openssl enc -aes-256-cbc -e -in $1 -out /dev/shm/bash-enc.tmp -K $key -iv $iv -base64
|
|
|
|
cat /dev/shm/bash-enc.tmp > $1
|
2024-03-18 16:11:27 +08:00
|
|
|
;;
|
|
|
|
"-d")
|
2024-03-18 16:19:35 +08:00
|
|
|
openssl enc -aes-256-cbc -d -in $1 -out /dev/shm/bash-enc.tmp -K $key -iv $iv -base64
|
|
|
|
cat /dev/shm/bash-enc.tmp > $1
|
2024-03-18 16:11:27 +08:00
|
|
|
;;
|
|
|
|
esac
|
2024-03-18 16:19:35 +08:00
|
|
|
shift
|
|
|
|
rm -f /dev/shm/bash-enc.tmp
|
2024-03-18 16:11:27 +08:00
|
|
|
done
|
2024-03-18 16:19:35 +08:00
|
|
|
|