code-dumps/sh/bash-enc.sh

29 lines
608 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")
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