PEM_read_RSA_PUBKEY返回并中断应用程序

PEM_read_RSA_PUBKEY returns and breaks the app

本文关键字:中断 应用程序 返回 PUBKEY read RSA PEM      更新时间:2023-10-16

我正在尝试使用RSA来使用OpenSSL加密一些内容。

RSA *rsaPubKey = RSA_new();
FILE *file;
file = fopen("PubKey.pem","r");
if(file){
    rsaPubKey = PEM_read_RSA_PUBKEY(file, &rsaPubKey ,NULL,NULL);
}
.......... //some stuff 
return 0

在执行PEM_read_RSA_PUBKEY之后,应用程序被终止,没有任何错误。我不知道怎么了!!

我在一个旧项目中使用了以下代码:

BIO *bioPub = BIO_new_file(pubkeyPath, "r");
RSA *pubkey = PEM_read_bio_PUBKEY(bioPub, NULL, NULL, NULL);
/* do some stuff */
RSA_free(pubkey);
BIO_free(bioPub);

你试过下面的吗?

FILE *file = fopen("PubKey.pem","r");
RSA *rsaPubKey = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL);