[vox-tech] GPG Symmetric Encryption - Noninteractively

Anshul Gupta vox-tech@lists.lugod.org
Wed, 14 Apr 2004 11:32:06 +1000


Hi All,

Can I do symmetric encryption non-interactively using gpg?

gpg -batch -ca doesn't seem to work as the key cannot be provided in 
some file or command line.

Tried writing a expect script,
#!/usr/bin/expect -d -f
#

set timeout -1
set send_slow {1 .1}
set send_human {.1 .3 1 .05 2}
spawn gpg -q -o message.enc -ca message
match_max 100000
expect -exact "Enter passphrase: "
send -- "ab\r"
expect -exact "\r                  \rRepeat passphrase: "
send -- "ab\r"
expect eof

This script works sometimes, hangs mostly after first/second passphrase 
has been sent. Tried "send -s/h" but they also fail.  What's wrong? Am 
I missing something?

Also if the expect script can read the input from stdin and write 
encrypted output to stdout, it would be great. Any help/suggestion is 
appreciated.

Thanks,
Anshul