diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2022-01-23 22:52:43 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2022-01-23 22:52:43 +0100 |
| commit | 0bc7e135aaf1600019c573509c3c801b9b1d6cb7 (patch) | |
| tree | 098530408fd7c86a048ee147c1e425329381c1da /secret | |
| parent | a26e6affc58beef0970287499a60ec8fbc5ea170 (diff) | |
| download | scripts-0bc7e135aaf1600019c573509c3c801b9b1d6cb7.tar.gz scripts-0bc7e135aaf1600019c573509c3c801b9b1d6cb7.zip | |
Added secret for password encrypting; changed default directory for sfeed-browser.
Diffstat (limited to 'secret')
| -rwxr-xr-x | secret | 48 |
1 files changed, 48 insertions, 0 deletions
| @@ -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 | |||
| 15 | opts="aes-256-cbc -iter 1000" # options for openssl | ||
| 16 | timeout=10 # timeout for clip, in ms | ||
| 17 | editor=${EDITOR:-vi} | ||
| 18 | |||
| 19 | if [ -z "$1" ] || [ -z "$2" ]; then | ||
| 20 | echo "usage: secret command file" | ||
| 21 | else | ||
| 22 | case "$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 | ;; | ||
| 47 | esac | ||
| 48 | fi | ||
