code-dumps/sh/bash-enc.sh

30 lines
667 B
Bash
Raw Normal View History

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