unsigned char * BUFFER_PTR;
CRYPT_CONTEXT cryptContext;
// Initialize the buffer
BUFFER_PTR = (unsigned char *) malloc(sizeof(char) * BUFFER_SIZE);
memset(BUFFER_PTR, 'X', BUFFER_SIZE);
//Initialize crytplib
cryptInit();
// c开发者_开发技巧reate encryption context
cryptCreateContext( &cryptContext, CRYPT_UNUSED, CRYPT_ALGO_ELGAMAL);
cryptSetAttributeString( cryptContext, CRYPT_CTXINFO_LABEL, KEY_ID, strlen(KEY_ID));
cryptGenerateKey(cryptContext);
/* ERROR >>>*/ cryptEncrypt(cryptContext, BUFFER_PTR, BUFFER_SIZE); /* this line fails and I don't know why :-( */
Googling for cryptlib CRYPT_ERROR_PARAM3
suggests that there was a problem with your third parameter. Now look at page 186 of the cryptlib manual, about CryptEncrypt
for public-key algorithms:
If the encrypted data length isn’t the same as the key size, the function will return CRYPT_ERROR_PARAM3 to indicate that the length is invalid.
I have never used cryptlib so this is an educated guess, but it looks rather like your plaintext isn't an appropriate size for the key you are using.
精彩评论