#!/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