【发布时间】:2014-04-16 11:47:32
【问题描述】:
我以这种方式使用 PEM_read_RSAPrivateKey 函数:
void test(void)
{
RSA * privateKey = NULL;
FILE * fp;
if(NULL != (fp= fopen("./my_file.key", "r")) )
{
privateKey=PEM_read_RSAPrivateKey(fp,NULL,NULL,NULL);
if(privateKey==NULL)
{
printf("\n\tCould NOT read RSA private key file");
}
else
{
printf("\n\tRSA structure filled");
}
// This is working OK and privateKey is NOT NULL
}
}
然后,我尝试检索模数和公共指数以将它们填充到个人结构中:
struct
{
unsigned char modulus[256];
unsigned char pub_exp[8];
} s;
但是我尝试(我尝试了很多)对 privateKey->n 的所有访问都会导致分段错误。
例如:
unsigned char modulus [2048];
unsigned char exp[2048];
BN_bn2bin(privateKey->n, modulus); // Segmentation fault results from this call
所以我的问题是:如何将模数或公共指数从 RSA 结构复制到我的结构“s”字段?
有人可以帮忙吗? 非常感谢, 问候,
西尔万
【问题讨论】:
-
有一个完整的 OpenSSL/RSA 测试程序,名为
test-rsa.c,位于 Private key generated by openssl does not satisfy n = p * q。这会让你崩溃吗?