Oh dear, sounds like you're in a right pickle.

Don't forget to call this first:

SSLeay_add_all_algorithms();

It fills out some structures in SSL library that may be the cause of
your problems (I had the same problems as you, and this fixed it, after
much debugging).

There's no need to call RSA_new() as the RSA_generate_key() allocates
the memory for you.

I am using ssl 0.9.0b, but I think it's more or less the same as
openssl.

Good luck!

Tat.

It fills in some static data in the crypto lib and may be the cause of
your problem.

"Andr0xL1A0zs_Joo/Digital_Reality/MSM/IBCGroup%IBCGROUP" wrote:
> 
> Hi, I'm a beginner programmer and I have been dropped into a big
> cryptographic project. My boss went away, and told me what to do still he
> comes back.
> I have to do the following things in C:
> 
> -generate an RSA key pair
> -write it out in a file in DER or PEM format
> 
> I tryed the following code:
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <openssl/rsa.h>
> 
> void main()
> {
>      RSA *rsa;
>      FILE *file;
>      int modulus_size = 1024;
>      int public_exponent = 65535;
>      RAND_screen();
>      rsa = RSA_new();
>      rsa = RSA_generate_key(modulus_size, public_exponent, NULL,NULL);
>      file=fopen("out.rsa","w");
>      PEM_write_RSAPrivateKey(file,rsa,NULL,NULL,0,NULL,NULL);
>      fclose(file);
> }
> 
> But I get a nice error box from Windows with the following: This program
> has performed an illegal operation, and will be closed....
> 
> The problem must be with the PEM_write_RSAPrivateKey.
> 
> What should I do ?
> Or if you can't tell how to write in DER format, then just simply tell how
> works the RSA_print_fp(..) function because I've got the same error message
> with it.
> 
> Thank you
> 
> Joo Andras
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]

-- 
+-----------------------------------
| Tat Sing Kong Bsc(Hons)               
| Senior Technical Architect            
| Consegna Advanced Technologies Ltd    
| 1st Floor, 30-32 Thomas Street        
| Manchester, M4 1ER, United Kingdom             
| http://www.consegna.co.uk       
| Tel : +44 (0)161 833 3777 (x30)     
| Fax : +44 (0)161 833 3636
| Email : [EMAIL PROTECTED]
begin:vcard 
n:Kong;Tat Sing
tel;fax:+44 (0)161 833 3636
tel;work:+44 (0)161 833 3777
x-mozilla-html:FALSE
url:www.consegna.co.uk
org:Consegna Advanced Technlogies Ltd
version:2.1
email;internet:[EMAIL PROTECTED]
title:Senior Software Architect
adr;quoted-printable:;;1st Floor=0D=0A30-32 Thomas Street=0D=0A;Manchester;;M4 1ER;
fn:Tat Sing Kong
end:vcard

S/MIME Cryptographic Signature

Reply via email to