I got it working
through,
pkey = (EVP_PKEY
*)PEM_ASN1_read((char *(*)())d2i_AutoPrivateKey,
PEM_STRING_EVP_PKEY,
fp, buff, NULL, NULL);
May be I am not sure that what I did was
correct.
In this case may I know why not to use PEM_ASN1_read rather than using
PEM_read_PrivateKey.
Thanks again for the immediate reply and for the
forth coming replies.
Murugesan
----- Original Message -----
Sent: Thursday, February 19, 2004 5:40
PM
Subject: Re: asn1 encoding
routines:d2i_PrivateKey:unknown public key type:d2i_pr.c:112
On Thu, Feb 19, 2004, murugesan
wrote:
> Hello all, > When I executed
the following program to read the private key it resulted in > >
Generating RSA private key, 512 bit long modulus >
....................++++++++++++ > ...............++++++++++++ > e
is 65537 (0x10001) > 13953:error:0D09A0A3:asn1 encoding
routines:d2i_PrivateKey:unknown public key type:d2i_pr.c:112: >
13953:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1
lib:pem_oth.c:82: > Assertion failed: evpkey!=0, file w.c, line
34 > Abort(coredump) > > #include <stdio.h> >
#include <string.h> > #include <openssl/rsa.h> >
#include <openssl/evp.h> > #include <openssl/err.h> >
#include <openssl/x509.h> > #include <openssl/pem.h> >
#include <sys/types.h> > #include <assert.h> >
> > EVP_PKEY * readkey(const char * keyfile) >
{ > FILE * fp = fopen(keyfile, "r"); >
char ** buff = NULL; > EVP_PKEY * pkey =
NULL; > if (!fp) > return
NULL; > pkey = (EVP_PKEY *)PEM_ASN1_read((char
*(*)())d2i_PrivateKey,
PEM_STRING_EVP_PKEY, >
fp, buff, NULL, NULL); > fclose (fp); > if
(pkey == NULL) >
ERR_print_errors_fp(stderr); > return pkey; >
} > > int main(int argc, char * argv[]) { >
const char * privatekey = "private.key"; > EVP_PKEY *
evpkey= NULL; > system("openssl genrsa -out
private.key"); >
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); >
ERR_load_crypto_strings(); > evpkey=
readkey(privatekey); >
assert(evpkey!=0); >
EVP_PKEY_free(evpkey); > return 0; > } >
>
Don't use PEM_ASN1_read(). Use PEM_read_PrivateKey()
instead.
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]
|