35 lines
777 B
Bash
35 lines
777 B
Bash
|
#!/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
|
||
|
|
||
|
if [[ $# -gt 20 ]]; then
|
||
|
echo "For safty reasons, encryption of up to 20 files is allowed"
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
OPER=$1
|
||
|
shift
|
||
|
|
||
|
while [[ $# -gt 0 ]];
|
||
|
do
|
||
|
case "$OPER" in
|
||
|
"-e")
|
||
|
openssl enc -aes-256-ctr -e -in $1 -out /dev/shm/bash-enc.tmp -K $key -iv $iv -base64
|
||
|
cat /dev/shm/bash-enc.tmp > $1
|
||
|
;;
|
||
|
"-d")
|
||
|
openssl enc -aes-256-ctr -d -in $1 -out /dev/shm/bash-enc.tmp -K $key -iv $iv -base64
|
||
|
cat /dev/shm/bash-enc.tmp > $1
|
||
|
;;
|
||
|
esac
|
||
|
shift
|
||
|
rm -f /dev/shm/bash-enc.tmp
|
||
|
done
|
||
|
|