OpenSSL私钥读取错误(PEM_read_bio_RSAPrivateKey)

时间:2022-12-28 18:26:16

I am trying to read a PrivateKey by openSSL and VC++, I am getting this error "OpenSSL error: error:0906D064:lib(9):func(109):reason(100)"..

我正在尝试阅读openSSL和VC++的私钥,我得到了这个错误“openSSL错误:错误:0906D064:lib(9):func(109):reason(100)”。

My Private Key :

我的私钥:

-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCnHVS+q65lvG2xocltTYgPGt9FaysGZTrcOwHedo8tX1dyPrcx
2I8x/cvB9nmfdAkt65aGFAlBZrofbPCr2Mq4wDdvIZ31KSuyMQI4T68ylWNT89Ge
wQF6AOkpY1E2bW+oDXc+MpbtpYXY1rUJAS/Abt5vXi7gwKN9FSJ3mm9bjQIDAQAB
AoGACXuxnmxRpjZOJ0FeE9TNfsXwm5jcRS2jbHHwxjYGI/YAGVyTusFmRtj3Iheh
iTnld3SiAxPJ/qscrsHY2nef8Up60V7RF8bs+sbICnHbdz8ZoKxN9dEFCwJkIl55
dv0GHjox6UgWUUkUAiHCM2EgG5eOOQ8PsuXY8LpPWLvfuyUCQQDbkFG9y/Q/3lmb
CdYfBpsP3qvma+fdgCw9lRXTowhu0rKen/CC3rFkHMeHfSW9GHuR8QbPYdVA6d9H
Y7KxYa7LAkEAwtjTEo/zAVexH/+YgiqL6w89BHlTAmwIEkXpqtAnE86kDDCekYdE
fRIdGK1zHDOUddMAhwoJQjJzy/NJreQ8BwJBAMoJ6U3vKZjD8Ex8Jq5yE6nsyt3D
mZ73XL5mO6l9sjrYY0kX/+dNKIro+KoyfNGef8bxtcSLUALlsnIsybf0HTUCQQCR
DD4cvGJHJpOp4WkTxT6Bjsd6lCKyU9+yUq8/RFNC0HqYxHzWkx7uCFT2sPBXFyK2
j4v9+v+ncs13DzZTJ+tzAkBI6UWHtsn839nrAT32M8PEPF/TuDmqebMhFOaTl4an
W0Jr8w8iGk2gvQS2cXEPNh4XT9AgcTKDQkhui4RgxK4F
-----END RSA PRIVATE KEY-----

My Code :

我的代码:

#include <openssl/rand.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/sha.h>

#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
#include <openssl/x509.h>


int main(int argc, char** argv)
{
    BIO *mem = NULL; 
    RSA *rsa_private = NULL;
    char *private_key = "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCnHVS+q65lvG2xocltTYgPGt9FaysGZTrcOwHedo8tX1dyPrcx2I8x/cvB9nmfdAkt65aGFAlBZrofbPCr2Mq4wDdvIZ31KSuyMQI4T68ylWNT89GewQF6AOkpY1E2bW+oDXc+MpbtpYXY1rUJAS/Abt5vXi7gwKN9FSJ3mm9bjQIDAQABAoGACXuxnmxRpjZOJ0FeE9TNfsXwm5jcRS2jbHHwxjYGI/YAGVyTusFmRtj3IhehiTnld3SiAxPJ/qscrsHY2nef8Up60V7RF8bs+sbICnHbdz8ZoKxN9dEFCwJkIl55dv0GHjox6UgWUUkUAiHCM2EgG5eOOQ8PsuXY8LpPWLvfuyUCQQDbkFG9y/Q/3lmbCdYfBpsP3qvma+fdgCw9lRXTowhu0rKen/CC3rFkHMeHfSW9GHuR8QbPYdVA6d9HY7KxYa7LAkEAwtjTEo/zAVexH/+YgiqL6w89BHlTAmwIEkXpqtAnE86kDDCekYdEfRIdGK1zHDOUddMAhwoJQjJzy/NJreQ8BwJBAMoJ6U3vKZjD8Ex8Jq5yE6nsyt3DmZ73XL5mO6l9sjrYY0kX/+dNKIro+KoyfNGef8bxtcSLUALlsnIsybf0HTUCQQCRDD4cvGJHJpOp4WkTxT6Bjsd6lCKyU9+yUq8/RFNC0HqYxHzWkx7uCFT2sPBXFyK2j4v9+v+ncs13DzZTJ+tzAkBI6UWHtsn839nrAT32M8PEPF/TuDmqebMhFOaTl4anW0Jr8w8iGk2gvQS2cXEPNh4XT9AgcTKDQkhui4RgxK4F\n-----END RSA PRIVATE KEY-----";

    mem = BIO_new_mem_buf(private_key, strlen(private_key));
    if (mem == NULL) 
    { 
        char buffer[120]; 
        ERR_error_string(ERR_get_error(), buffer); 
        fprintf(stderr, "OpenSSL error: %s", buffer);
        exit(0);
    } 

    rsa_private = PEM_read_bio_RSAPrivateKey(mem, NULL, NULL, NULL); 
    BIO_free (mem); 
    if (rsa_private == NULL) 
    { 
        char buffer[120]; 
        ERR_error_string(ERR_get_error(), buffer); 
        fprintf(stderr, "OpenSSL error: %s", buffer);
        exit(0);
    } 

    return(0);

}

I am using WinXP-SP2 and MS-Visual Studio 2008.. I am getting error in this line : rsa_private = PEM_read_bio_RSAPrivateKey(mem, NULL, NULL, NULL); Error : (OpenSSL error: error:0906D064:lib(9):func(109):reason(100))

我正在使用WinXP-SP2和MS-Visual Studio 2008。在这一行我得到了错误:rsa_private = PEM_read_bio_RSAPrivateKey(mem, NULL, NULL, NULL, NULL);错误:(OpenSSL错误:错误:0906D064:lib(9):func(109):reason(100)))

Any one can help me, how should I read this privet key ????

谁能帮我一个忙,我该怎么看这把女贞钥匙??

Thanks.....

由于.....

1 个解决方案

#1


3  

The variable private_key is initialized wrongly. You need to add \n after each line in your Private Key.

变量private_key初始化错误。您需要在私钥的每行之后添加\n。

#1


3  

The variable private_key is initialized wrongly. You need to add \n after each line in your Private Key.

变量private_key初始化错误。您需要在私钥的每行之后添加\n。