From aaee3c8df14e4d369807541055c55fa06265d551 Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Sun, 22 Mar 2015 23:13:02 -0700 Subject: [PATCH] add openssl encrypt / decrypt wrappers Signed-off-by: Colin McCabe --- dec.sh | 31 +++++++++++++++++++++++++++++++ enc.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-) create mode 100755 dec.sh create mode 100755 enc.sh 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 -- 1.6.6.rc1.39.g9a42