From f287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 20 Sep 2017 21:19:05 +0200 Subject: Commit current state --- utils/encrypt | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 utils/encrypt (limited to 'utils/encrypt') diff --git a/utils/encrypt b/utils/encrypt new file mode 100644 index 0000000..d1cb938 --- /dev/null +++ b/utils/encrypt @@ -0,0 +1,42 @@ +# vim:ft=sh:noexpandtab +# Allows work with encrypted files using their temporally copy. + +if [ -n "$KEY_FILE" ] && [ -f "files/keys/$(hostname)" ]; then + SECRET_KEY="$(openssl aes-192-cbc -d -a -kfile "$KEY_FILE" -in files/keys/"$(hostname)")" +else + SECRET_KEY="$(gpg2 --decrypt files/keys/primary.gpg)" +fi + +# Decrypt to temporally file in /tmp +# First argument should be the path to file to be decrypted and second argument +# output file. +fdecrypt() { + PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -d -a -pass env:PASS_ENC -in "$1" -out "$2" +} + +# Encrypt given file to target path +# First argument have to be a path to file to be encrypted and second argument +# output file. +fencprypt() { + PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -e -a -pass env:PASS_ENC -in "$1" -out "$2" +} + +# Decrypt file to temporally one +# First argument have to be path to file to be extracted. +tfdecrypt() { + local TEMPF="$(mktemp /tmp/multiconfig_XXXXXXXX)" + fdecrypt "$1" "$TEMPF" + echo "$TEMPF" +} + +# Cat decrypted file +# First argument have to be a path to file to be catted. +catdecrypt() { + PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -d -a -pass env:PASS_ENC -in "$1" +} + +# Encrypt stdin to file +# First argument have to be a path to output file. +outencrypt() { + PASS_ENC="$SECRET_KEY" openssl aes-192-cbc -e -a -pass env:PASS_ENC -out "$2" +} -- cgit v1.2.3