On Tue, Apr 27, 2004, Carlos Roberto Zainos H wrote:
> Hi Dr Henson and openssl users list.
>
> I'm very thankful by your answers.
>
> This time I'm having problems with the d2i_PKCS8PrivateKey_bio function. This always
> returns me 0 , and really I don't know what's wrong.
> My code:
> RSA *rsa;
> EVP_PKEY *dec_key, **x=NULL;
> BIO *in=NULL;
> char *password = "am01key";
> char *priv_key_der = "llaveAMp5.key";/*PBE privkey file */
> int i,size_llave=0;
>
> OpenSSL_add_all_algorithms();
> ERR_load_crypto_strings();
>
> in=BIO_new(BIO_s_file());
> if (in==NULL) /*not problem */
> {
> /* Error code*/
> }
>
> if (BIO_read_filename(in,priv_key_der) <= 0) /*not problem*/
> {
> /*Error Code*/
> }
>
> /*dec_key=EVP_PKEY_new(); comment this because I thought could be the problem*/
> dec_key=d2i_PKCS8PrivateKey_bio(in, x, NULL,password);
> if (dec_key=NULL) /*also not problem*/
> {
> /*Error code */
> }
>
> size_llave=EVP_PKEY_size(dec_key); /*result of this function is always 0 */
> printf("%d\n", size_llave); /*prints zero 0 */
>
> rsa=RSA_new();
> rsa=EVP_PKEY_get1_RSA(dec_key); /*this function breaks because dec_key is 0 size
> bytes, right ? */
>
> With all my test keys the results are the same (privkeyp5.key,
> privkeyp8.key, privkey_der.key). Is there some type of bug ? Or this is
> caused by my C code??
>
Yep its your C code. That line:
if (dec_key=NULL)
will *set* dec to NULL which will cause the problems later on. You should do:
if (dec_key == NULL)
Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]