GPGME:无效的加密引擎

GPGME : Invalid crypto engine

我正在尝试检查在 C++ 项目上使用 gpgme,但是当我尝试访问 OpenPGP 引擎时

我已经在我的电脑上安装了 GnuPG,我 运行 在 windows 下。

更多命令 gpgconfgpg2 工作正常,因此 GnuGP 安装良好

我将 gpgme 的调试级别设置为 9,但我收到了一个错误日志:

GPGME 2015-12-28 19:05:21 <0x2b18>  gpgme_debug: level=9
GPGME 2015-12-28 19:05:21 <0x2b18>  gpgme_debug: gpgme='D:\CODING\C++\bin\Debug'
GPGME 2015-12-28 19:05:21 <0x2b18>  gpgme_check_version: call: 0=00000000, req_version=(null), VERSION=1.6.0
GPGME 2015-12-28 19:05:21 <0x2b18>  gpgme_check_version_internal: call: 0=00000000, req_version=(null), offset_sig_validity=32
GPGME 2015-12-28 19:05:21 <0x2b18>  gpgme-dinfo: gpgconf='C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe'
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_pipe: enter: filedes=0028F680, inherit_idx=1 (GPGME uses it for reading)
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_pipe: leave: read=0x0 (00000150/0x0), write=0x1 (00000164/0x0)
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: enter: path=0AF93FD0, path=C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, argv[ 0] = C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, argv[ 1] = --list-dirs
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, tmp_name = C:\Users\User\AppData\Local\Temp\gpgme-HBCBJ6
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, CreateProcess failed: ec=87
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: error: Input/output error
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: enter: fd=00000000
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: check: fd=00000000, fd=0 -> handle=00000150 socket=-1 dupfrom=-1
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: leave: result=0
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: enter: fd=00000001
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: check: fd=00000001, fd=1 -> handle=00000164 socket=-1 dupfrom=-1
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: leave: result=0
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_pipe: enter: filedes=0028F680, inherit_idx=1 (GPGME uses it for reading)
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_pipe: leave: read=0x0 (00000168/0x0), write=0x1 (00000174/0x0)
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: enter: path=0AF93FD0, path=C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, argv[ 0] = C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, argv[ 1] = --list-components
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, tmp_name = C:\Users\User\AppData\Local\Temp\gpgme-4Cb3i3
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, CreateProcess failed: ec=87
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: error: Input/output error
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: enter: fd=00000000
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: check: fd=00000000, fd=0 -> handle=00000168 socket=-1 dupfrom=-1
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: leave: result=0
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: enter: fd=00000001
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: check: fd=00000001, fd=1 -> handle=00000174 socket=-1 dupfrom=-1
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: leave: result=0
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_pipe: enter: filedes=0028FA5C, inherit_idx=1 (GPGME uses it for reading)
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_pipe: leave: read=0x0 (0000017C/0x0), write=0x1 (00000190/0x0)
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: enter: path=0AF93FD0, path=C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, argv[ 0] = C:\Program Files (x86)\GNU\GnuPG\gpgconf.exe
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, argv[ 1] = --version
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, tmp_name = C:\Users\User\AppData\Local\Temp\gpgme-DrOuSZ
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: check: path=0AF93FD0, CreateProcess failed: ec=87
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_spawn: error: Input/output error
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: enter: fd=00000000
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: check: fd=00000000, fd=0 -> handle=0000017C socket=-1 dupfrom=-1
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: leave: result=0
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: enter: fd=00000001
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: check: fd=00000001, fd=1 -> handle=00000190 socket=-1 dupfrom=-1
GPGME 2015-12-28 19:05:21 <0x2b18>  _gpgme_io_close: leave: result=0
GPGME 2015-12-28 19:05:21 <0x2b18>  engine.c:365: returning error: Invalid crypto engine
GPGME 2015-12-28 19:05:21 <0x2b18>  engine.c:155: returning error: Invalid crypto engine
Invalid crypto engine

编辑: 这是我 运行 的代码:

#include "gpgme.h"
#include <iostream>
using namespace std;

void genKey()
{
    gpgme_set_global_flag("debug","9");
    gpgme_check_version(NULL);
    gpg_error_t test = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
    cout << gpgme_strerror(test) << endl;
    cout << "Engine : " << gpgme_get_dirinfo("gpg-name") << endl;
}

已解决:


我在虚拟目录中安装了 gpg4win,我将整个目录复制到我的 bin 中。我在 gpgme_check_version(NULL) 之前添加 gpgme_set_global_flag("disable-gpgconf","1")gpgme_set_global_flag("gpg-name","gpgconf")
现在可以使用了,谢谢。