#include <openssl/rsa.h>
int main()
{
RSA *r;
int bits=512,ret;
unsigned long e=RSA_3;
BIGNUM *bne;
r=RSA_generate_key(bits,e,NULL,NULL);
RSA_print_fp(stdout,r,11);
RSA_free(r);
bne=BN_new();
ret=BN_set_word(bne,e);
r=RSA_new();
ret=RSA_generate_key_ex(r,bits,bne,NULL);
if(ret!=1)
{
printf("RSA_generate_key_ex err!\n");
return -1;
}
RSA_free(r);
return 0;
}
说明:
调用RSA_generate_key和RSA_generate_key_ex函数生成RSA密钥,
调用RSA_print_fp打印密钥信息。
输出:
Private-Key: (512 bit)
modulus:
00:d0:93:40:10:21:dd:c2:0b:
77:79:ed:a9:a4:10:66:6e:88:d6:9b:0b:
23:
b4:d7:ab:66:3e:73:d7:78:00:e6:
c2:9b:c7:e2:c3
publicExponent: 3 (0x3)
privateExponent:
00:8b:
17:
d3:19:
84:
prime1:
00:f7:
59:27:
46:
prime2:
00:d7:e9:88:
ba:96:44:29:74:3e:b9:
c7:65:
exponent1:
00:a4:dd:fd:48:cc:6e:f8:3d:73:9d:d6:83:fe:d1:
90:c4:f1:
d9:74:b3
exponent2:
00:
da:43:
coefficient:
00:d3:fa:ea:a0:21:7e:
5d:10:96:17:69:75:cd:71:d5:e5:07:26:93:e8:35:
ca:e3:49