Ricardo Guerra wrote: > > hi all, > > i have this piece of code, it crashes on PEM_write_RSA_PUBKEY (segfault), > it's the same if i use PEM_write_rsa_PublicKey instead.. > does anyone have any idea about how to fix it? > > i've created the private key with openssl grnrsa -out priv.key 1024 > > thanks. > > Ricardo > > RSA *privKey ; > FILE *file; > if ((file=fopen(name, "rb"))== NULL) > return 0; > > privKey = *PEM_read_RSAPrivateKey(file, NULL, NULL, NULL); > fclose(file); > > file=fopen(name,"user.pub"); > > PEM_write_RSA_PUBKEY(file,&privKey); > fclose(file);
You are using invalid arguments in the functions (your compiler is probably giving various warnings about invalid types) and the second fopen call is clearly wrong. PEM_read_RSAPrivateKey returns RSA * so you need to do: privKey = PEM_read_RSAPrivateKey(file, NULL, NULL, NULL, NULL); similarly you should do: PEM_write_RSA_PUBKEY(file, privKey); Steve. -- Dr Stephen N. Henson. http://www.drh-consultancy.demon.co.uk/ Personal Email: [EMAIL PROTECTED] Senior crypto engineer, Gemplus: http://www.gemplus.com/ Core developer of the OpenSSL project: http://www.openssl.org/ Business Email: [EMAIL PROTECTED] PGP key: via homepage. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]