错误:从'int'转换为非标量类型'BIGNUM {aka bignum_st}'请求

时间:2014-11-27 15:05:38

标签: c++ openssl

我正在尝试在Linux下使用openssl g++函数

 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);

here所述。我的示例程序如下:

RSA *rsa;
BIGNUM e = 7;
if (!RSA_generate_key_ex(rsa, 1024, e)) {
   cout << "error" << endl;
}

但是我在编译期间得到的错误是

src/test.cpp: In function ‘int main(int, char**)’:
src/test.cpp:29:15: error: conversion from ‘int’ to non-scalar type ‘BIGNUM {aka bignum_st}’ requested
src/test.cpp:30:41: error: cannot convert ‘BIGNUM {aka bignum_st}’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘3’ to ‘int RSA_generate_key_ex(RSA*, int, BIGNUM*, BN_GENCB*)’
make: *** [build/test.o] Error 1

我不知道BIGNUM是什么,也没有在链接页面上描述。

1 个答案:

答案 0 :(得分:3)

您需要提供BIGNUM*

BIGNUM *e = BN_new();
BN_set_word(e, 7);
if (!RSA_generate_key_ex(rsa, 1024, e, cb)) { /* ... */ }
BN_clear_free(e);

如果您不知道应如何定义cb,请将其替换为NULL。也就是说,

RSA_generate_key_ex(rsa, 1024, e, NULL)
相关问题