将 GPG 与 C 结合使用?

发布于 2024-12-25 09:05:33 字数 175 浏览 4 评论 0原文

我正在用 C 语言编写一个通信程序,并且正在寻找使用 GnuPG 加密的最佳方法。我已经通过 mcrypt 库使用对称加密算法,但希望合并一些公钥功能,如果可能的话最好使用 GnuPG。有没有一个好的库可以完成这个任务?尝试通过程序直接与 GPG 本身交互来完成此任务会更好吗?任何见解将不胜感激,因为我希望保持此实现尽可能干净。谢谢。

I am writing a communication program in C and I am looking for the best way to use GnuPG encryption. I am already using symmetric encryption algorithms via the mcrypt library but wish to incorporate some public-key capabilities, preferably using GnuPG if possible. Is there a good library available to accomplish this? Would it be better to try to interact with GPG itself directly via the program to accomplish this? Any insight would be appreciated as I would like to keep this implementation as clean as possible. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

调妓 2025-01-01 09:05:33

不幸的是,GnuPG 被设计为交互使用,而不是作为 API。

您提到您正在寻求整合一些公钥功能。 SSL 和 TLS 是 GPG 的替代品,使用频率更高。

如果您通常需要公共密钥功能,GnuTLS 是一个用于网络中的 API基于的程序可以准确提供您想要的内容。它享有大量支持,并提供 SSL 和 TLS 公钥加密功能。

但是,如果您执意要使用 GPG,GPGME 是一个项目它的存在是为了围绕 GPG 封装 API。我没有使用过它,也无法建议它的使用,但怀疑它可能有些强迫。

Unfortunately, GnuPG is designed to be used interactively, and not as an API.

You mention that you are looking to incorporate some public-key capabilities. SSL and TLS are alternatives to GPG which see much more frequent use.

If public-key capabilities in general are what you seek, GnuTLS is an API for use in network based programs that provides exactly what you want. It enjoys a great deal of support, and provides SSL and TLS public-key encryption capabilities.

However, if you are dead set on using GPG, GPGME is a project that exists to wrap an API around GPG. I have not used it and cannot advise on its use, but suspect that it may be somewhat forced.

奈何桥上唱咆哮 2025-01-01 09:05:33

GPGme 确实是GPG 的官方 API,并且易于使用且文档齐全(tests/gpg 中的示例非常有帮助)

这是约翰·史密斯的加密示例:

gpgme_data_t clear_text, encrypted_text;
gpgme_key_t recipients[2] = {NULL, NULL}; 
       /* The array must be NULL-terminated */
...
error = gpgme_op_keylist_start(context, "John Smith", 1);
error = gpgme_op_keylist_next(context, &recipients[0]);
...
error = gpgme_op_encrypt(context, recipients, 
               GPGME_ENCRYPT_ALWAYS_TRUST, 
                           clear_text, encrypted_text);

GPGme is indeed the official API for GPG and is easy to use and well documented (the examples in tests/gpg are very helpful)

Here is an example to encrypt for John Smith:

gpgme_data_t clear_text, encrypted_text;
gpgme_key_t recipients[2] = {NULL, NULL}; 
       /* The array must be NULL-terminated */
...
error = gpgme_op_keylist_start(context, "John Smith", 1);
error = gpgme_op_keylist_next(context, &recipients[0]);
...
error = gpgme_op_encrypt(context, recipients, 
               GPGME_ENCRYPT_ALWAYS_TRUST, 
                           clear_text, encrypted_text);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文