Cryptlib 不会使用 El-Gamal 加密,我不明白为什么?
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();
// create 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 :-( */
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();
// create 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 :-( */
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谷歌搜索 cryptlib CRYPT_ERROR_PARAM3 表明您的第三个参数存在问题。现在看看 cryptlib 手册的第 186 页,关于公钥算法的
CryptEncrypt
:我从未使用过 cryptlib,所以这是一个有根据的猜测,但看起来您的明文大小不适合您正在使用的密钥。
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, aboutCryptEncrypt
for public-key algorithms: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.