枯音未来 2016-03-29 11:58
浏览 3310
已结题

PEM_read_bio_RSAPrivateKey的返回值为NULL

我是要用OPENSSL编写私钥解密部分,但在使用函数PEM_read_bio_RSAPrivateKey()的返回值为NULL。
以下是我的代码:
void rsadecrption(unsigned char cipher[],CString Path)
{CFile fc;
CFileException e;
if(!fc.Open(Path,CFile::modeCreate | CFile::modeWrite|CFile::shareExclusive|CFile::typeBinary,&e))
{
//AfxMessageBox("打开fp失败");
return;
}
EVP_PKEY* evpkey;
RSA *rsa=NULL;
BIO *key = NULL;
unsigned long len;
char dir[2048]={NULL};
memcpy(dir,Path,1024); //ques
for(int i=0;i<1024;i++)
{
if(i%2==0)
dir[i/2]=dir[i];
}
ERR_load_crypto_strings(); //from Internet
key = BIO_new(BIO_s_file());
BIO_read_filename(key,dir);
rsa = PEM_read_bio_RSAPrivateKey(key, NULL, NULL, NULL); //返回值为NULL
BIO_free_all(key);

if(rsa==NULL){
    printf("unable to read private key!\n");
    return; 
}   

len = RSA_size( rsa );
unsigned char sign[4096]={NULL};
//int Len=strlen(cipher);
int block=1024/256;
//int remain=1024%256;
for(int i=0;i<block;i++)
{
    if(RSA_private_decrypt(256,sign,cipher,rsa,RSA_PKCS1_PADDING)<=0)
        return;
    fc.Write(sign,128);
}   
//fwrite(cipher,strlen(sign),1,fc);
fc.Close();

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
    • ¥15 钢筋实图交点识别,机器视觉代码
    • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
    • ¥50 400g qsfp 光模块iphy方案
    • ¥15 两块ADC0804用proteus仿真时,出现异常
    • ¥15 关于风控系统,如何去选择
    • ¥15 这款软件是什么?需要能满足我的需求
    • ¥15 SpringSecurityOauth2登陆前后request不一致
    • ¥15 禅道二次开发编辑版本,上传不了发行包