Sorry,

I forget put in the flen parameter of the function
RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to,
RSA *rsa, int padding);  the value returned by the
RSA_public_encrypt(...), but I have not solved the problem with the
function
int RSA_print_fp(FILE *fp, RSA *x, int offset).

Someboy can help me?

Thanks.

On 4/13/05, Tyler Durden <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> I have a problem wiht the function
> "int RSA_private_decrypt(int flen, unsigned char *from, unsigned char
> *to, RSA *rsa, int padding);"
> 
> When I call this function after to call the RSA_public_encrypt, I get
> -1 return value, therefore I get an error. The information error is:
> 
> <LIB>: rsa routines
> <FUNC>: RSA_padding_check_SSLv23
> <REASON>: block type is not 02
> 
> I don't understand because this erros occur, because I use the padding
> type when encypt that  when decrypt.
> 
> On the other hand, I get a segmentation fault when I use the function
> "int RSA_print_fp(FILE *fp, RSA *x, int offset);" and I don't know the reason.
> 
> Teh souce code that I am using is this:
> 
> #include <iostream>
> #include <openssl/rsa.h>
> #include <openssl/err.h>
> 
> /*
> RSA *RSA_generate_key(int num, unsigned long e,
>     void (*callback)(int,int,void *), void *cb_arg);
> 
>         int RSA_print_fp(FILE *fp, RSA *x, int offset);
> */
> 
> void rsa_callback( int arg1, int arg2, void *cb_arg )
> {
> }
> 
> int main( int argc, char** argv )
> {
>         ERR_load_crypto_strings();
>         RSA *rsaKeys = RSA_generate_key( 1024, 3, rsa_callback, NULL );
> 
>         unsigned char datain[] = "test of the rsa1";
>         unsigned char *dataout = new unsigned char[RSA_size( rsaKeys )-11];
> 
>     if( rsaKeys == NULL )
>         {
>                 std::cout << "The rsa key is NULL" << std::endl;
>                 return -1;
>         }
> 
>         if( RSA_check_key( rsaKeys ) <= 0 )
>         {
>                 std::cout << "The rsa key is not valid" << std::endl;
>                 return -1;
>         }
> 
>         if( RSA_public_encrypt( sizeof( datain ), datain, dataout, rsaKeys,
> RSA_PKCS1_PADDING ) == -1 )
>         {
>                 int error = ERR_get_error();
>                 std::cout << "<LIB>: " << ERR_lib_error_string( error )<< 
> std::endl;
>                 std::cout << "<FUNC>: " << ERR_func_error_string( error )<< 
> std::endl;
>                 std::cout << "<REASON>: " << ERR_reason_error_string( error 
> )<< std::endl;
>                 return -2;
>         }
> 
>         unsigned char *decryptData = new unsigned char[RSA_size( rsaKeys )];
> 
>         if( RSA_private_decrypt(RSA_size( rsaKeys )-11, dataout, decryptData,
> rsaKeys, RSA_PKCS1_PADDING ) == -1 )
>         {
>                 int error = ERR_get_error();
>                 std::cout << "<LIB>: " << ERR_lib_error_string( error )<< 
> std::endl;
>                 std::cout << "<FUNC>: " << ERR_func_error_string( error )<< 
> std::endl;
>                 std::cout << "<REASON>: " << ERR_reason_error_string( error 
> )<< std::endl;
>                 return -2;
>         }
> 
>         std::cout << decryptData << std::endl;
> 
>         FILE *fRsaKey = fopen( "rsaKey.txt", "wb" );
>         RSA_print_fp( fRsaKey, rsaKeys, 1 );
> 
>         ERR_free_strings();
>         return 1;
> }
>
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to