gpgme: encrypt/decrypt

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


From: "Werner Koch" <wk at gnupg.org>
> 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
do
> > what I want to do here?  I'm creating a Postfix content filter for the
> > company that automatically does GPG encryption/decryption on incoming
and
>
> 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.

Hmm...so... 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]

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2 (GNU/Linux)

mQGiBEMBnIcRBACbXdplRQM9iXWf30OQZqWSfT69+t5lflpvLnKehQt4FaSrxJj/
EwmsTtf7PiOm2Cjp727HUlr12gSkVWwwBT+mnUD+oqpM6Gzl6pcolzoEWHzCMwFH
TTMvdnUzYTI81aY2wMTHx016IbdTeO3qZ4nQGxz95IyH1Lx+6kkinK//zwCg2Q5U

[...]

I then do the following:

err = gpgme_data_new_from_mem (&pubKey, z.gpgPublic, strlen(z.gpgPublic),
1);
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?


Michael





More information about the Gnupg-devel mailing list