Quantcast

error making Private RSA

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

error making Private RSA

MrUmunhum
Hello group,
I am attempting to create a Private RSA structure with the following code:
 BIO*
  PEM = BIO_new_mem_buf( Key, Key_Len );

  if( Type == 1 )
     PEM_write_bio_RSAPrivateKey( PEM, RSA, NULL, NULL, 0, NULL, NULL );
  else
     PEM_write_bio_RSAPublicKey(  PEM, RSA );

  if( RSA_check_key( RSA ) != 1 )  {
    printf( RED "Make %s RSA Failed\n" OFF, Type==1?"Private":"Public" );
    int Error  = ERR_get_error();
    char *MSG  = ERR_error_string( Error, NULL);
    printf( "%s\n", MSG );  }

and I get this error:
Make Private RSA Failed
error:2007507E:lib(32):func(117):reason(126)
Can anyone tell me what this error is and how to fix it?


--
William Estrada
Mt Umunhum, CA, USA, Earth
HTTP:// Mt-Umunhum-Wireless.net
Skype: MrUmunhum

--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error making Private RSA

Matt Caswell-2


On 02/03/17 00:47, william estrada wrote:

> Hello group,
> I am attempting to create a Private RSA structure with the following code:
>  BIO*
>   PEM = BIO_new_mem_buf( Key, Key_Len );
>
>   if( Type == 1 )
>      PEM_write_bio_RSAPrivateKey( PEM, RSA, NULL, NULL, 0, NULL, NULL );
>   else
>      PEM_write_bio_RSAPublicKey(  PEM, RSA );
>
>   if( RSA_check_key( RSA ) != 1 )  {
>     printf( RED "Make %s RSA Failed\n" OFF, Type==1?"Private":"Public" );
>     int Error  = ERR_get_error();
>     char *MSG  = ERR_error_string( Error, NULL);
>     printf( "%s\n", MSG );  }
>
> and I get this error:
> Make Private RSA Failed
> error:2007507E:lib(32):func(117):reason(126)
> Can anyone tell me what this error is and how to fix it?
>
>

$ openssl errstr 2007507E
error:2007507E:BIO routines:mem_write:write to read only BIO

BIO_new_mem_buf() gives you a read-only BIO. You probably want
BIO_new(BIO_s_mem()) instead.

See:

https://www.openssl.org/docs/man1.1.0/crypto/BIO_s_mem.html

Although, that error is coming from one of the PEM_write_bio_* calls
(which you are not checking the error return code of), so it doesn't
explain why RSA_check_key() fails. You don't show how you generate the
RSA structure to start with, so I guess you're not generating it properly.

Matt
--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error making Private RSA

OpenSSL - User mailing list
In reply to this post by MrUmunhum
What version of openssl?  I'm guessing 1.0.2.

Put this line inyour code
        ERR_load_ERR_strings();
And youll get a more informative message.

My main guess is that your allocation for the PEM buffer is too small -- is key/key_len pointing to a static buffer?
--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
Loading...