# 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" }