开发者

Cryptlib won't encrypt with El-Gamal and I don't understand why?

开发者 https://www.devze.com 2023-03-05 06:39 出处:网络
unsigned char * BUFFER_PTR; CRYPT_CONTEXT cryptContext; // Initialize the buffer BUFFER_PTR = (unsigned char *) malloc(sizeof(char) * BUFFER_SIZE);
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消