我使用PEM_read_RSAPrivateKey功能以這樣的方式PEM_read_RSAPrivateKey:獲取RSA密鑰公共模數和指數
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結構複製模量或公用指數到我的結構「的」領域?
有人可以幫忙嗎? 非常感謝, 問候,
西爾
有一個完整的OpenSSL/RSA測試程序名爲'test-rsa.c'位於[由openssl生成的私鑰不滿足n = p * q](http://stackoverflow.com/questions/22119835/private -key生成逐OpenSSL的-不-未滿足-NPQ)。這會對你造成什麼影響嗎? – jww