Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created January 21, 2017 23:04
Show Gist options
  • Save mwgamera/bcf0d7c470d6b9b3ea7ba1888bdc33fd to your computer and use it in GitHub Desktop.
Save mwgamera/bcf0d7c470d6b9b3ea7ba1888bdc33fd to your computer and use it in GitHub Desktop.
#!/usr/bin/es --
# Password-based encryption with GPG2
# klg, Dec 2016
fn easkpass {
* = $* 'Password: '
<>/dev/tty >[1=0] let (
g = `{stty -g}
)
unwind-protect {
stty sane -echo
printf '\r%s\e[K' $1
$&read
} {
echo
stty $g
}
}
fn with-passfd fun {
let (fd = <=%newfd)
%pipe {$&echo <=easkpass} 1 $fd {$fun $fd}
}
let (
mode = $1;
argv = (
--no-options
--no-default-keyring --keyring /dev/null
--no-random-seed-file
--no-autostart
--s2k-count 10000000
) $*(2 ...)
) {
if {~ $mode -e -c} {
argv = --symmetric $argv
} {~ $mode -d} {
argv = --decrypt $argv
} {
echo >[1=2] Usage: $0 '[-e|-d]' ...
exit 1
}
with-passfd @ {(
gpg2
--passphrase-fd $1
--pinentry-mode loopback
$argv
)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment