I have a Java application which gets GnuPG encrypted files from a remote machine and I need to decrypt and process them. Then I need to encrypt output files and send it to remote machine.
At first I tried gnupg-for-java
(https://github.com/guardianproject/gnupg-for-java). It works, but it prompts me for passwords to decrypt file and to sign encrypted file. In documentation there is "With GnuPG 2.x, gpg-agent will handle prompting the user for the passphrase, as well as passphrase caching."
Do you know how can I provide password without prompting user?
Use gpg-preset-passphrase
, which is usually located in /usr/lib/gnupg2/gpg-preset-passphrase
(and not on the default path). It should also be installed with the usual distributions of GnuPG on Windows and OS X.
Be aware you will have to allow presetting the passphrase by setting the allow-preset-passphrase
option in the ~/.gnupg/gpg-agent.conf
file (create it if necessary, and restart gpg-agent
afterwards). Also, do not use the --passphrase
option on multiuser systems, every also non-privileged user can read all other application's arguments. Provide the passphrase on STDIN instead.