简体   繁体   English

将GPG与C一起使用?

[英]Using GPG with C?

I am writing a communication program in C and I am looking for the best way to use GnuPG encryption. 我正在用C编写通信程序,我正在寻找使用GnuPG加密的最佳方法。 I am already using symmetric encryption algorithms via the mcrypt library but wish to incorporate some public-key capabilities, preferably using GnuPG if possible. 我已经通过mcrypt库使用对称加密算法,但希望结合一些公钥功能,如果可能的话,最好使用GnuPG。 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? 尝试直接通过程序与GPG本身进行交互以实现这一目标会更好吗? Any insight would be appreciated as I would like to keep this implementation as clean as possible. 任何见解都将受到赞赏,因为我希望尽可能保持这种实施。 Thanks. 谢谢。

Unfortunately, GnuPG is designed to be used interactively, and not as an API. 不幸的是, GnuPG旨在以交互方式使用,而不是作为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. SSL和TLS是GPG的替代品,可以更频繁地使用。

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. 如果您寻求的是公共密钥功能, GnuTLS是一种用于基于网络的程序的API,可以提供您想要的内容。 It enjoys a great deal of support, and provides SSL and TLS public-key encryption capabilities. 它享有很多支持,并提供SSL和TLS公钥加密功能。

However, if you are dead set on using GPG, GPGME is a project that exists to wrap an API around GPG. 但是,如果你没有使用GPG, 那么GPGME就是一个用于围绕GPG封装API的项目。 I have not used it and cannot advise on its use, but suspect that it may be somewhat forced. 我没有使用它,也无法就其使用提出建议,但怀疑它可能有点被迫。

GPGme is indeed the official API for GPG and is easy to use and well documented (the examples in tests/gpg are very helpful) GPGme确实是GPG官方API,易于使用且文档齐全(测试/ gpg中的示例非常有用)

Here is an example to encrypt for John Smith: 以下是加密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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM