This is what I up to,

$ openssl genrsa -out private.pem 2048
$ openssl rsa -in private.pem -out public.pem -pubout

to gen the private & public keys 

pvk_fd = fopen("private.pem","r");
rsa_pv = PEM_read_RSAPrivateKey(pvk_fd,&rsa_pv,NULL,NULL);
ret = RSA_sign(NID_md5,testString,15,authMsg,siglen,rsa_pv);

........

pbk_fd = fopen("public.pem","r");
rsa_pb = PEM_read_RSA_PUBKEY(pbk_fd,&rsa_pb,NULL,NULL);
ret = RSA_verify(NID_md5,testString,15,authMsg,*siglen,rsa_pb);

By dummping public modulus & exponent from both private and public keys, they 
are the same. RSA_sign/verify does not work. What did I miss?

Thanks.

Sonia



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Marek Marcola
Sent: Monday, July 03, 2006 8:57 AM
To: [email protected]
Subject: RE: Private Key Type and PEM Length


Hello,
> I want to read public part of RSA. 
> The input file is PEM format file generated by openssl genrsa 
> for private and openssl rsa for public.
> Do you mean this is not the correct format for PEM_read_RSAPublicKey?
Yes, PEM_read_RSAPublicKey require PKCS#1 but if public key was
generated with command like:
        $ openssl genrsa -out rsa.pem 1024 (PKCS#1 format)
        $ openssl rsa -in rsa.pem -out rsapub.pem -pubout
this public key (rsapub.pem) is encoded in SubjectPublicKeyInfo format.
For reading this format you may use PEM_read_RSA_PUBKEY
witch should read this public key.

You may check difference with encoded format executimg commands like:
        $ openssl asn1parse -in rsa.pem
        $ openssl asn1parse -in rsapub.pem

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to