2 u010997137 u010997137 于 2016.03.29 19:58 提问

PEM_read_bio_RSAPrivateKey的返回值为NULL 10C

我是要用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();

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!