gpgme: encrypt/decrypt

Michael Nguyen michaeln at
Wed Aug 17 01:49:15 CEST 2005

From: "Werner Koch" <wk at>
> On Tue, 16 Aug 2005 11:22:19 -0700, Michael Nguyen said:
> > I guess this is more of a program design question.  Should I be able to
> > what I want to do here?  I'm creating a Postfix content filter for the
> > company that automatically does GPG encryption/decryption on incoming
> Everyone seems to write this kind of software tehse days ;-)
> For various reasons, GnuPG requires access to the full keyring.
> Just import everything once and you are basically set.  No deen t
> duplicate the data. are you saying I can't do it this way?  Ok, bear with me
here...this is what I've done so far:

So, I've read my test public key into a string that's a member of a user
struct called z.gpgPublic

[sample of public key so that we're very clear on the format here]

Version: GnuPG v1.4.2 (GNU/Linux)



I then do the following:

err = gpgme_data_new_from_mem (&pubKey, z.gpgPublic, strlen(z.gpgPublic),
err = gpgme_op_import (ctx, pubKey);

So, will this really import the key?  It seems to because I can find my
email address:

  while (!(err = gpgme_op_keylist_next (ctx, &key)))
        if(strcmp(z.primaryEmail, key->uids->email) == 0)
                printf ("%s\n", key->uids->email);

Basically I take this loop and I say "If you see the email address of the
user, print it".  It always comes up so it seems to work.  So, am I going
about this the right way so far?  If so, how do I correctly call
gpgme_op_encrypt() at this point?


More information about the Gnupg-devel mailing list