GPGME, problem in exporting a key

Björn Mayer bjorn.mayer at
Thu May 25 17:35:05 CEST 2006

  Hi folks,

  I have a problem in exporting a public key within GPGME 1.1.2!
  The problem is, that everything seems to be correct but it's not
  working. I would like to export the public key of the key owner
  named "name". When I enter
     gpg --export -a "name"

  everything is handled correct and a public key is displayed. But
  within gpgme, the export process always fails:

  (for reasons of a better readability, I only write down the
   important error handling)
  bool exportPublicKey(string fpr){
     gpgme_ctx_t ctx;
     gpgme_error_t err;

     if(!startSession(ctx))		// initialize a new context
       return false;

     gpgme_data_t  out;
     err = gpgme_data_new (&out);				// ok

     const char *pattern = "name";
     gpgme_set_armor(ctx, 1);
     err = gpgme_op_export(ctx, pattern, 0, out); 	// seems to be ok

     int ret = gpgme_data_seek(out, 0, SEEK_SET);
     if (ret){
       cout << ret;
       err = gpgme_err_code_from_errno (errno);	
       if(err){							// fails
         cout << "\n --> Exception in function \"exportPublicKey\"		
              <<  \n      " + string(gpgme_strerror (err)) + "\n";
         return false;

     char buf[BUF_SIZE + 1];
     while ((ret = gpgme_data_read (out, buf, BUF_SIZE)) > 0)
       fwrite (buf, ret, 1, stdout);

     gpgme_data_release (out);
     return true;

  The output is always "-1" (value of ret) as well as
   --> Exception in function "exportKey"
        Invalid argument

  I've no idea what the reason is, cause in GPG itself, everything
  seems to be correct. Does anyone of you guys have an idea?

  Best regards from Tuebingen/Germany,

More information about the Gnupg-devel mailing list