读取公共密钥成功但是读取私密密钥失败
密钥生成代码
- C/C++ code
BIO *bp = BIO_new(BIO_s_file()); if(BIO_write_filename(bp, (void *)("public.pem"))<=0) { qDebug("write error\n"); exit(-1); } if(PEM_write_bio_RSAPublicKey(bp, rsa)!=1) { qDebug("write public key error\n"); exit(-1); } qDebug("保存公钥成功\n"); BIO_free_all(bp); unsigned char passwd[]="abc"; // 私钥 bp = BIO_new_file("private.pem", "w"); if(PEM_write_bio_RSAPrivateKey(bp, rsa, EVP_des_ede3(), passwd, 3, NULL, NULL)!=1) { qDebug("write public key error\n"); exit(-1); }
私密密钥读取代码
- C/C++ code
RSA *rsaK; OpenSSL_add_all_algorithms(); BIO *BP=BIO_new(BIO_s_file()); char FileName[]="private.pem"; int ret=BIO_read_filename(BP,FileName); qDebug()<<ret; char PSW[]="abc"; rsaK=PEM_read_bio_RSAPrivateKey(BP,NULL,NULL,PSW);//这个返回值是0
------解决方案--------------------
顶一下,我也想知道经过3des加密的私钥文件怎么读取
saK=PEM_read_bio_RSAPrivateKey(BP,NULL,NULL,PSW);//这个返回值是0 //这里的第三个参数肯定是需要传递的,但是不知道怎么写