Hi,
I generate a pem file that content rsa private key encripted with rc4 algorithm
But when i would read a pem file this not accepted the password (obviously I introduce 
the same password in the two functions :) )
Can anyone help me?
Thanks,
lidia

//----------------------GENKEYS------------------------------------------------//
void genera_claves(unsigned char *pass)
{
 RSA *clave;
 BIO *publica;
 BIO *privada;
 EVP_CIPHER *algoritmo;
 publica=BIO_new(BIO_s_file());
 privada=BIO_new(BIO_s_file());
 
if (BIO_write_filename(publica,"publica.pem") <= 0) 
    {
         perror("ERROR: publica.pem");
         exit(0);
    }

 if (BIO_write_filename(privada,"privada.pem") <= 0) 
    {
                     perror("ERROR: privada.pem");
                     exit(0);
    }
 clave=RSA_generate_key(1024,3,NULL,NULL); 

 if (PEM_write_bio_RSAPublicKey(publica,clave) > 0) 
 {     
      printf("Clave pública RSA guardada\n");
    
  }
    
 algoritmo=EVP_rc4();    
 if (PEM_write_bio_RSAPrivateKey(privada,clave,algoritmo,pass,16,NULL,NULL) > 0) 
{
           printf("Clave privada RSA protegida con una clave RC4\n");
           
 }

 RSA_free(clave);
 BIO_free(publica);  
BIO_free(privada);
}

//-------------------------------------READ PEM 
FILE----------------------------------------
void lee_privada(unsigned char *pass)
{
RSA *clave;
BIO *privada;

SSLeay_add_all_algorithms();
ERR_load_PEM_strings();


privada=BIO_new(BIO_s_file());
if (BIO_read_filename(privada,"privada.pem") <= 0)
{
             
   perror("ERROR: privada.pem");
             exit(0);
}
if ((clave=PEM_read_bio_RSAPrivateKey(privada,NULL,NULL,pass)) != NULL) 
{
                printf("Clave privada RSA leida correctamente.\n");
                RSA_free(clave);
}
else
 printf("no he leido");
BIO_free(privada);
}

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to