gpg --genkey
is an interactive call, which waits for input, which you never provide. Two possible solutions:
- Use bouncycastle instead, which is a native Java library for OpenPGP.
As implementing an interactive GnuPG session will be rather complicated and error-prone, you might better use the "experimental feature" for batch key generation. From
man gpg
:--gen-key Generate a new key pair. This command is normally only used interactively. There is an experimental feature which allows you to create keys in batch mode. See the file `doc/DETAILS' in the source distribution on how to use this.
The file
doc/DETAILS
is also available online. The section you want to look up is called "Unattended key generation". It's rather lengthy, so I didn't quote it here, but this is the example from the document on how to do it:$ cat >foo <<EOF %echo Generating a basic OpenPGP key Key-Type: DSA Key-Length: 1024 Subkey-Type: ELG-E Subkey-Length: 1024 Name-Real: Joe Tester Name-Comment: with stupid passphrase Name-Email: joe@foo.bar Expire-Date: 0 Passphrase: abc %pubring foo.pub %secring foo.sec # Do a commit here, so that we can later print "done" :-) %commit %echo done EOF $ gpg --batch --gen-key foo