首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C GPGMe忽略用户密钥环

C GPGMe忽略用户密钥环
EN

Stack Overflow用户
提问于 2015-04-16 13:43:54
回答 1查看 515关注 0票数 3

我最近完成了一个将公钥下载到内存中的程序,然后用它们创建一个加密消息。但是,我在创建一个只下载密钥的列表时遇到了一些困难。当它们第一次下载时,它们被存储在gpgme_data_t中。我无法找到一个直接将其转换为gpgme_key_t的函数。因此,我将它们导入到一个新的上下文中。但是,当我再次导出密钥以便为gpgme_op_encrypt构建一个列表时,我最终使用了本地密钥环中的其他密钥。我试着设置disable-gpgconf,但这并没有改变任何事情。我还尝试将GNUPGHOME设置为tmp目录,但当我调用encrypt时,这导致了分段错误。是否有方法不导入用户的密钥环或将gpgme_data_tchar*转换为gpgme_key_t

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-26 00:02:50

有没有办法不导入用户的密钥环?

为了防止加载用户密钥环,您需要将上下文的GnuPG homedir设置为其他地方。

下面是一个没有错误检查的示例

代码语言:javascript
复制
#include <gpgme.h>
#include <locale.h>

int main() {
    gpgme_ctx_t ctx;  // the context
    gpgme_error_t err; // errors
    gpgme_key_t key; // the key
    gpgme_keylist_result_t result; // the keylist results

    setlocale (LC_ALL, ""); // set the locale
    gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); // set gpgme locale
    gpgme_check_version(NULL); // initialize gpgme

    gpgme_new (&ctx); // initialize the context

    gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_OpenPGP, NULL, "/tmp/xyz"); // set the context GNUPGHOME to "/tmp/xyz"

    gpgme_op_keylist_start (ctx, NULL, 0); // start the keylist

    while (!(err = gpgme_op_keylist_next (ctx, &key))) { // loop through the keys in the keyring
        fprintf(stdout, "Key ID: %s\n", key->subkeys->keyid); // print out the keyid
        gpgme_key_unref (key); // release the key reference
    }

    gpgme_release(ctx); // release the context, all done

    return 0;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29676626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档