From: Colin Patrick Mccabe Date: Mon, 23 Mar 2015 06:13:02 +0000 (-0700) Subject: add openssl encrypt / decrypt wrappers X-Git-Url: http://www.club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?p=cmccabe-bin;a=commitdiff_plain;h=aaee3c8df14e4d369807541055c55fa06265d551 add openssl encrypt / decrypt wrappers Signed-off-by: Colin McCabe --- diff --git a/dec.sh b/dec.sh new file mode 100755 index 0000000..ef4aaa1 --- /dev/null +++ b/dec.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +die() { + echo $@ + exit 1 +} + +[ "x${SALT}" = "x" ] && die "you must set SALT to the salt." +[ "x${PASS}" = "x" ] && die "you must set PASS to the password" + +RET=0 +for FILE in "$@"; do + if [[ "${FILE}" = *.nc ]]; then + BASE_FILE="$(dirname ${FILE})/$(basename ${FILE} .nc)" + if [ -e "${BASE_FILE}" ]; then + echo "Not decrypting $FILE because there is already a ${BASE_FILE}" + else + if openssl enc -d -aes-256-ecb \ + -S "$SALT" \ + -k "$PASS" < "${FILE}" > "${BASE_FILE}"; then + echo "Created ${BASE_FILE}" + else + echo "Failed to create ${BASE_FILE}" + RET=1 + fi + fi + else + echo "Not decrypting $FILE because its name does not end in .nc" + fi +done +exit $RET diff --git a/enc.sh b/enc.sh new file mode 100755 index 0000000..a0ec8ef --- /dev/null +++ b/enc.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +die() { + echo $@ + exit 1 +} + +[ "x${SALT}" = "x" ] && die "you must set SALT to the salt." +[ "x${PASS}" = "x" ] && die "you must set PASS to the password" + +RET=0 +for FILE in "$@"; do + if [[ "${FILE}" = *.nc ]]; then + echo "Not encrypting ${FILE} because its name already ends in .nc" + else + NEW_FILE="${FILE}.nc" + if [ -e "${NEW_FILE}" ]; then + echo "Not encrypting ${FILE} because there is already a ${NEW_FILE}" + else + if openssl enc -aes-256-ecb \ + -S "${SALT}" \ + -k "${PASS}" < "${FILE}" > "${NEW_FILE}"; then + echo "Created ${NEW_FILE}" + else + echo "Failed to create ${NEW_FILE}" + RET=1 + fi + fi + fi +done +exit $RET