I've seen this in a few other circumstances too, but first let's make
absolutely sure the OS allows you to create that file: add a check for
privateKeyFile==NULL _before_ you use that FILE handle - as you should ;-)

So that would mean something along these lines (code from my head, i.e.
untested):

privateKeyFile = fopen("Privatekey", "w");
if (privateKeyFile == NULL)
{
  /* might be handy to print the errno value too! */
  fprintf(stderr, "Fatal error: cannot create/open file '%s' for writing:
%s\n", "Privatekey", strerror(errno));
  exit(EXIT_FAILURE); // abort test app
}
else
{
  PEM_write_RSAPrivateKey(privateKeyFile, r,NULL,NULL, 0,NULL, NULL);
  ...
  // don't forget to close the handle:
  fclose(privateKeyFile);
}
// done


Hope this helps you along,

Ger




On Sun, Mar 16, 2008 at 8:53 PM, learning openssl <
[EMAIL PROTECTED]> wrote:

>  I use VS2005 to create a private RSA key. But I always get the error from
> the file setmode.c  line 58: Expression: (_osfile(fh)&FOPEN) --Debug
> assertion failed
>
>
>     RSA *r =NULL;
>     int bits=512;
>     unsigned long e=RSA_3;
>     FILE *privateKeyFile;
> r=RSA_generate_key(bits,e,NULL,NULL);
> fopen_s(&privateKeyFile,"Privatekey", "w"); //privateKeyFile =
> fopen("Privatekey", "w");
> PEM_write_RSAPrivateKey(privateKeyFile, r,NULL,NULL, 0,NULL, NULL);
>
> The error comes from the function PEM_write_RSAPrivateKey().
>
> Please help me!
>
> ------------------------------
> Express yourself instantly with MSN Messenger! MSN 
> Messenger<http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>
>



-- 
Met vriendelijke groeten / Best regards,

Ger Hobbelt

--------------------------------------------------
web: http://www.hobbelt.com/
http://www.hebbut.net/
mail: [EMAIL PROTECTED]
mobile: +31-6-11 120 978
--------------------------------------------------

Reply via email to