blob: 0554bdb38ea4400945f77c0c5a85a762b76b24b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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, xsel (for clip only)
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
|