Page MenuHome GnuPG

Invalid Crypto Engine
Closed, InvalidPublic

Description

I have to use GPG for windows.For that i have installed GPG4Win in my system and try to use it through C++ code using DLL libgpgme-glib-11.
Getting "Invalid crytpto Engine" while calling "gpgme_engine_check_version".
Plz find the code snippet::
void _stdcall LoadGPG()
{
gpgme_error_t error;
char* p;
gpgme_key_t recipients[2] = {NULL, NULL};
gpgme_data_t clear_text, encrypted_text;
gpgme_encrypt_result_t result;
gpgme_engine_info_t info;
gpgme_keylist_mode_t keymode;
gpgme_protocol_t proto;

	  static char dir[MAX_PATH+5];

GetModuleFileName (NULL, (LPWSTR)dir, MAX_PATH);
/* Initialize the locale environment. */
setlocale(LC_ALL, "");
int n =gpgme_set_global_flag("disable-gpgconf","1");
n = gpgme_set_global_flag("gpg-name","gpgme-w32spawn");
n = gpgme_set_global_flag("bindir","C://Program Files (x86)GNUGnuPG");

	 p = (char *) gpgme_check_version (NULL);//to initialize gpg

	
	 "C:\\Program Files (x86)\\GNU\\GnuPG");

gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
#ifdef LC_MESSAGES
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
#endif
gpgme_ctx_t *context = (gpgme_ctx_t *)malloc(sizeof *context);
error = gpgme_new(context);
error = gpgme_set_protocol (*context, GPGME_PROTOCOL_OpenPGP);

keymode = gpgme_get_keylist_mode(*context);
info = gpgme_ctx_get_engine_info(*context);

/* Setting the output type must be done at the beginning */
gpgme_set_armor(*context, 1);

	   /* Initializes the context */

const char*openpgp = gpgme_get_dirinfo("gpg-name");

const char*engineconfigurationtool = gpgme_get_dirinfo("bindir");

engineconfigurationtool = gpgme_get_dirinfo("g13-name");

error = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP,"C:\\Program Files (x86)\\GNU\\GnuPG\\gpgconf.exe","C:\\Users\\g516302\\AppData\\Roaming\\gnupg");
const char *pEngineinfoerror1 = gpgme_strerror(error) ;

error = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
gpgme_err_code_t errcode = gpgme_err_code_from_errno(error);
const char * str = gpgme_strsource(error);
pEngineinfoerror1 = gpgme_strerror(error) ;
error = gpgme_error_from_errno(error);
const char* locale = _gpg_w32_gettext_localename();

const char *perror1 = gpgme_strerror(error) ;
gpgme_key_t * const keys = new gpgme_key_t[ 2 ];
gpgme_data_t data;
gpgme_data_t cipher;

	 gpgme_error_t e = gpgme_data_new(&data);
	 e = gpgme_data_new(&cipher);

gpgme_data_set_file_name(data, "C:\\Logs\\test.txt");
error= gpgme_op_encrypt(*context,0,(gpgme_encrypt_flags_t)0,data,cipher);
pEngineinfoerror1 = gpgme_strerror(error) ;

}

Details

Version
libgpgme-glib-11 ver 1.6.0

Event Timeline

werner added a subscriber: werner.

This is a question on how to install and use gpgme. Please direct this to the gnupg-devel mailing list.

Please avoid the use of gpgme_set_global_flag - this is rarely useful

n = gpgme_set_global_flag("gpg-name","gpgme-w32spawn");

That is definitely not going to work. Examples on how to use gpgme can be found in the tests directory.

where i can found the Test Directory