From 0bc7e135aaf1600019c573509c3c801b9b1d6cb7 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 23 Jan 2022 22:52:43 +0100 Subject: Added secret for password encrypting; changed default directory for sfeed-browser. --- secret | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 secret (limited to 'secret') diff --git a/secret b/secret new file mode 100755 index 0000000..2b4d470 --- /dev/null +++ b/secret @@ -0,0 +1,48 @@ +#!/bin/sh + +# Encrypt and decrypt files using a fixed cipher and passphrase. +# The first line of the (unencrypted) file is considered the "password", the +# rest can be anything. + +# Usage: secret command file +# Available commands: +# clip: copy the secret to clipboard; deleted after 10 seconds +# edit: edit or add a file +# show: show the full encrypted file + +# Requires: openssl + +opts="aes-256-cbc -iter 1000" # options for openssl +timeout=10 # timeout for clip, in ms +editor=${EDITOR:-vi} + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "usage: secret command file" +else +case "$1" in + clip) + openssl $opts -d < "$2" | head -n 1 | xargs printf "%s" | xsel -ib + sleep $timeout && xsel -db & + ;; + edit) + tempfile=$(mktemp) + if [ -f "$2" ]; then + openssl $opts -d < "$2" > "$tempfile" + fi + $editor "$tempfile" + read -p "Are you sure? [N/yes] " an + if [ "$an" = yes ] || [ "$an" = Yes ] || [ "$an" = YES ]; then + openssl $opts < "$tempfile" > "$2" + else + echo "Changes discarded" + fi + rm "$tempfile" + ;; + show) + openssl $opts -d < "$2" + ;; + *) + echo "$1: not a valid command" + ;; +esac +fi -- cgit v1.3