aboutsummaryrefslogtreecommitdiff
path: root/secret
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2022-01-23 22:52:43 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2022-01-23 22:52:43 +0100
commit0bc7e135aaf1600019c573509c3c801b9b1d6cb7 (patch)
tree098530408fd7c86a048ee147c1e425329381c1da /secret
parenta26e6affc58beef0970287499a60ec8fbc5ea170 (diff)
downloadscripts-0bc7e135aaf1600019c573509c3c801b9b1d6cb7.tar.gz
scripts-0bc7e135aaf1600019c573509c3c801b9b1d6cb7.zip
Added secret for password encrypting; changed default directory for sfeed-browser.
Diffstat (limited to 'secret')
-rwxr-xr-xsecret48
1 files changed, 48 insertions, 0 deletions
diff --git a/secret b/secret
new file mode 100755
index 0000000..2b4d470
--- /dev/null
+++ b/secret
@@ -0,0 +1,48 @@
1#!/bin/sh
2
3# Encrypt and decrypt files using a fixed cipher and passphrase.
4# The first line of the (unencrypted) file is considered the "password", the
5# rest can be anything.
6
7# Usage: secret command file
8# Available commands:
9# clip: copy the secret to clipboard; deleted after 10 seconds
10# edit: edit or add a file
11# show: show the full encrypted file
12
13# Requires: openssl
14
15opts="aes-256-cbc -iter 1000" # options for openssl
16timeout=10 # timeout for clip, in ms
17editor=${EDITOR:-vi}
18
19if [ -z "$1" ] || [ -z "$2" ]; then
20 echo "usage: secret command file"
21else
22case "$1" in
23 clip)
24 openssl $opts -d < "$2" | head -n 1 | xargs printf "%s" | xsel -ib
25 sleep $timeout && xsel -db &
26 ;;
27 edit)
28 tempfile=$(mktemp)
29 if [ -f "$2" ]; then
30 openssl $opts -d < "$2" > "$tempfile"
31 fi
32 $editor "$tempfile"
33 read -p "Are you sure? [N/yes] " an
34 if [ "$an" = yes ] || [ "$an" = Yes ] || [ "$an" = YES ]; then
35 openssl $opts < "$tempfile" > "$2"
36 else
37 echo "Changes discarded"
38 fi
39 rm "$tempfile"
40 ;;
41 show)
42 openssl $opts -d < "$2"
43 ;;
44 *)
45 echo "$1: not a valid command"
46 ;;
47esac
48fi

Generated with cgit - Back to sebastiano.tronto.net