aboutsummaryrefslogtreecommitdiff
path: root/utils/encrypt
diff options
context:
space:
mode:
Diffstat (limited to 'utils/encrypt')
-rw-r--r--utils/encrypt42
1 files changed, 42 insertions, 0 deletions
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"
+}