首页 新闻 搜索 专区 学院

RSA_private_decrypt(rsa_len, str, decrypted, rsa2,RSA_PKCS1_PADDING);解密失败

0
悬赏园豆:20 [已关闭问题] 关闭于 2016-10-19 15:39

错误信息:

RSA_private_decrypt: No such file or directory,这里面哪有文件啊?求解惑

问题补充:

解密代码:

#define PRIKEY "./prikey.pem"
char *decrypted=NULL;
char *my_decrypt(unsigned char *str, char *prikey_path)
{
OpenSSL_add_all_algorithms();//有些算法必须这样初始化。
//打开私钥文件
FILE* priv_fp=fopen(PRIKEY,"r");
if(priv_fp==NULL){
printf("failed to open PRIKEY file %s!\n", PRIKEY);
return NULL;
}
// 从文件中读取私钥
RSA *rsa2 = PEM_read_RSAPrivateKey(priv_fp, NULL, NULL, NULL);
if(rsa2==NULL){
printf("unable to read private key!\n");
return NULL; 

// 用私钥解密
int rsa_len = RSA_size(rsa2);
printf("rsa_len: %d\n", rsa_len);
//char *decrypted=NULL;
decrypted = (char *)malloc(1024);
memset(decrypted, 0, 1024);
printf("strlen(str): %d\n", strlen(str));
int len=RSA_private_decrypt(rsa_len, str, decrypted, rsa2,RSA_PKCS1_PADDING);// RSA_NO_PADDING
if(len==-1){
perror("RSA_private_decrypt:");
return NULL;
}
fclose(priv_fp);
return decrypted;
}

life清者自清的主页 life清者自清 | 初学一级 | 园豆:76
提问于:2016-10-17 10:50
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册