At least with gpg2 2.1.4-1 and gpgme 1.5.5-2 the passphrase callback
does not work.
When enabled I get the "secret key unusable" error, and without the
callback (enter passphrase via agent) it works fine.
If I remember correctly you stated that you need gpg2 v2.1 or better
for that to work:
https://lists.gnupg.org/pipermail/gnupg-devel/2015-May/029872.html
Steps:
download http://vps001.vanheusden.com/~folkert/gbug.tgz
unpack it
make
Then:
./gpgme_test E96F346A94A761F898F9DA35D8CD7D21B2A93EF9 test4.txt 1f28d8ae
First parameter is your key-id, second is a text-file containing your
passphrase and the third is the pubkey for which it will sign and
encrypt.
The output looks like:
2015-07-04 18:55:50 (FIXME) GPGME version: 1.5.5
2015-07-04 18:55:50 (FIXME) GPGME protocol: OpenPGP, exe: /usr/bin/gpg2, home-
dir: (null), version: 2.1.4, req version: 1.4.0
2015-07-04 18:55:50 (FIXME) GPGME protocol: CMS, exe: /usr/bin/gpgsm, home-dir:
(null), version: (null), req version: 2.0.4
2015-07-04 18:55:50 (FIXME) GPGME protocol: GPGCONF, exe: /usr/bin/gpgconf,
home-dir: (null), version: 2.1.4, req version: 2.0.4
2015-07-04 18:55:50 (FIXME) GPGME protocol: Assuan, exe:
/home/folkert/.gnupg/S.gpg-agent, home-dir: !GPG_AGENT, version: 1.0,
req version: 1.0
2015-07-04 18:55:50 (FIXME) GPGME protocol: UIServer, exe:
/home/folkert/.gnupg/S.uiserver, home-dir: (null), version: 1.0, req version:
1.0
2015-07-04 18:55:50 (FIXME) GPGME protocol: Spawn, exe: /nonexistent, home-dir:
(null), version: 1.0, req version: 1.0
2015-07-04 18:55:50 (FIXME) my_key_id_in:
E96F346A94A761F898F9DA35D8CD7D21B2A93EF9, found key: D8CD7D21B2A93EF9
2015-07-04 18:55:50 (FIXME) gpgme init success
get_my_keyid: 1
key known: 1
error:
2015-07-04 18:55:50 (FIXME) my_key: D8CD7D21B2A93EF9
encrypt: 0
error: gpgme_op_encrypt failed: Unusable secret key (117440566)
The "error:" without anythin behind it can be ignored.