RE: PEM_read_RSA_PUBKEY() & PEM_read_RSAPublicKey()

2013-08-27 Thread Dave Thompson
> From: owner-openssl-us...@openssl.org On Behalf Of Dr. Stephen Henson
> Sent: Tuesday, 27 August, 2013 08:10

Adding a little:

> On Tue, Aug 27, 2013, Cyberman Wu wrote:
> 
> > I've tried both to load public key from PEM file, but
> > PEM_read_RSAPublicKey() failed.
> > 
> 
> It would help if you said what error you get or posted the file.
> 
> See also:
> 
> http://www.openssl.org/support/faq.html#PROG6
> 
Preferably #PROG7 also, although that's not vital.

> > I can't get any information from manual
> 
> The pem manual pages gives information:
> 
> http://www.openssl.org/docs/crypto/pem.html
> 
>  The RSAPublicKey functions process an RSA public key using 
> an RSA structure.
>  The public key is encoded using a PKCS#1 RSAPublicKey structure.
> 
>  The RSA_PUBKEY functions also process an RSA public key using an RSA
>  structure. However the public key is encoded using a 
> SubjectPublicKeyInfo
>  structure and an error occurs if the public key is not RSA. 
> 
And PEM can easily be distinguished by the dash lines:
RSAPublicKey is "BEGIN/END RSA PUBLIC KEY" while RSA_PUBKEY 
(and also DSA_PUBKEY etc) is "BEGIN/END PUBLIC KEY".

The same two structures are supported in DER, and there if 
you lose track which is which you have to asn1parse and grovel.

Usually PUBKEY is more likely because it is the default for 
commandline utilities like rsa -pubout and x509 -pubout .
Though >=1.0.0 rsa has undocumented options for RSAPublicKey.


__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: PEM_read_RSA_PUBKEY() & PEM_read_RSAPublicKey()

2013-08-27 Thread Dr. Stephen Henson
On Tue, Aug 27, 2013, Cyberman Wu wrote:

> I've tried both to load public key from PEM file, but
> PEM_read_RSAPublicKey() failed.
> 

It would help if you said what error you get or posted the file.

See also:

http://www.openssl.org/support/faq.html#PROG6

> I can't get any information from manual

The pem manual pages gives information:

http://www.openssl.org/docs/crypto/pem.html

 The RSAPublicKey functions process an RSA public key using an RSA structure.
 The public key is encoded using a PKCS#1 RSAPublicKey structure.

 The RSA_PUBKEY functions also process an RSA public key using an RSA
 structure. However the public key is encoded using a SubjectPublicKeyInfo
 structure and an error occurs if the public key is not RSA. 

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


PEM_read_RSA_PUBKEY() & PEM_read_RSAPublicKey()

2013-08-27 Thread Cyberman Wu
I've tried both to load public key from PEM file, but
PEM_read_RSAPublicKey() failed.

I can't get any information from manual, so I've googled a lot, and
got that opnion:

=
You might try PEM_read_RSA_PUBKEY() instead of PEM_read_RSAPublicKey().

This is all about formats.

The default public key file format generated by openssl is the PEM format.

PEM_read_RSA_PUBKEY() reads the PEM format. PEM_read_RSAPublicKey()
reads the PKCS#1 format.

So if you want to stick to PEM_read_RSAPublicKey() you could generate
the public key file using the PKCS#1 format by specifying the -outform
DER option when generating the public key.
=
(From 
http://stackoverflow.com/questions/7818117/why-i-cant-read-openssl-generated-rsa-pub-key-with-pem-read-rsapublickey)


But it's PEM_xxx, why it used to read from DER format? Then I tried it
on DER format, but it still failed.

So, where should I use that it?


BTW: where is the source code of that two APIs? I've grep all the
files under openssl, but only doc and./util/libeay.num.


-- 
Cyberman Wu
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


R: R: PEM_read_RSAPublicKey problem

2008-07-01 Thread Marco Sommella
No no i do it correct.
PEM_read_RSAPrivateKey()
RSA_sign()

For sign and:

PEM_read_RSAPublicKey()
RSA_verify()

For verify

-Messaggio originale-
Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Per conto di Kenneth Goldman
Inviato: lunedì 30 giugno 2008 14.58
A: openssl-users@openssl.org
Oggetto: Re: R: PEM_read_RSAPublicKey problem

Perhaps the problem is that you're reading the public key and
trying to sign.  Signing uses a private key.

Try:

PEM_read_RSAPrivateKey()
RSA_sign()

[EMAIL PROTECTED] wrote on 06/27/2008 11:31:42 AM:

> Excuse me,
> I'm trying, using C, to do a simple sign and verify with RSA public and
> private keys on pem files.
> Which is the easy way?
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: R: PEM_read_RSAPublicKey problem

2008-07-01 Thread Kenneth Goldman
Perhaps the problem is that you're reading the public key and
trying to sign.  Signing uses a private key.

Try:

PEM_read_RSAPrivateKey()
RSA_sign()

[EMAIL PROTECTED] wrote on 06/27/2008 11:31:42 AM:

> Excuse me,
> I'm trying, using C, to do a simple sign and verify with RSA public and
> private keys on pem files.
> Which is the easy way?
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


R: PEM_read_RSAPublicKey problem

2008-06-27 Thread Marco Sommella
Excuse me,
I'm trying, using C, to do a simple sign and verify with RSA public and
private keys on pem files.
Which is the easy way?
Someone have some sample ?
TNX

-Messaggio originale-
Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Per conto di David Schwartz
Inviato: venerdì 27 giugno 2008 5.41
A: openssl-users@openssl.org
Oggetto: RE: PEM_read_RSAPublicKey problem


> hi again,
> i created a publickey.pem with command:
> openssl rsa -in myprivate.pem -pubout -out publickey.pem
>
> then in C i try to read this public key with:
> RSA *pubkey = PEM_read_RSAPublicKey(fp, NULL, NULL, NULL)
>
> where fp is the opened publickey.pem file.
>
> but it's return this error: error:0906D06C:lib(9):func(109):reason(108)
>
> where i'm wrong ?

Hmm:

error:0906D06C:PEM routines:PEM_read_bio:no start line

I believe you are mixing types. 'openssl rsa -pubout' writes out a key in
X.509 subjectPublicKeyInfo format. PEM_read_RSAPublicKey expects a raw RSA
key.

You have the same problem this guy had:
http://mail.nl.linux.org/tinc/2004-02/msg7.html

DS


__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


RE: PEM_read_RSAPublicKey problem

2008-06-26 Thread David Schwartz

> hi again,
> i created a publickey.pem with command:
> openssl rsa -in myprivate.pem -pubout -out publickey.pem
>
> then in C i try to read this public key with:
> RSA *pubkey = PEM_read_RSAPublicKey(fp, NULL, NULL, NULL)
>
> where fp is the opened publickey.pem file.
>
> but it's return this error: error:0906D06C:lib(9):func(109):reason(108)
>
> where i'm wrong ?

Hmm:

error:0906D06C:PEM routines:PEM_read_bio:no start line

I believe you are mixing types. 'openssl rsa -pubout' writes out a key in
X.509 subjectPublicKeyInfo format. PEM_read_RSAPublicKey expects a raw RSA
key.

You have the same problem this guy had:
http://mail.nl.linux.org/tinc/2004-02/msg7.html

DS


__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


PEM_read_RSAPublicKey problem

2008-06-26 Thread Marco Sommella

hi again,
i created a publickey.pem with command:
openssl rsa -in myprivate.pem -pubout -out publickey.pem

then in C i try to read this public key with:
RSA *pubkey = PEM_read_RSAPublicKey(fp, NULL, NULL, NULL)

where fp is the opened publickey.pem file.

but it's return this error: error:0906D06C:lib(9):func(109):reason(108)

where i'm wrong ?

TNX
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-13 Thread Marek . Marcola
Hello,

> One thing I will conform you is " we can not get public key from a 
private key ". I do 
> not remember where i studied , but it is true.
> So do not try to get a public key from private key.
This is not true.

Best regards,
--
Marek Marcola <[EMAIL PROTECTED]>
 
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-13 Thread Th�nh Trung Nguyễn
Thanks !
I forgot the FAQ, sorry !

"Dr. Stephen Henson" <[EMAIL PROTECTED]> wrote: On Sat, Apr 12, 2008, Thnh 
Trung Nguyễn wrote:

> Hi !
> 
> I used PEM_write_RSAPrivateKey() to write private key to a pem file.
> Then I used PEM_read_RSAPublicKey() to read public key from that file, but it 
> returned an error.
> The ERR_error_string() only return message like :
> error:0906D06C:lib(9):func(109):reason(108)
> So can any one tell me can i use PEM_read_RSAPublicKey() to load public key 
> from a private key ?

You can't as they are incompatible structures. However you can *use* a private
key anywhere you'd use a public key because the private key contains all the
public key components.

> And are the any way to get human understandable error message ?
> 

Read the FAQ.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Homepage: http://www.drh-consultancy.demon.co.uk
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]



trungnt
 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-13 Thread Dr. Stephen Henson
On Sat, Apr 12, 2008, Thnh Trung Nguyễn wrote:

> Hi !
> 
> I used PEM_write_RSAPrivateKey() to write private key to a pem file.
> Then I used PEM_read_RSAPublicKey() to read public key from that file, but it 
> returned an error.
> The ERR_error_string() only return message like :
> error:0906D06C:lib(9):func(109):reason(108)
> So can any one tell me can i use PEM_read_RSAPublicKey() to load public key 
> from a private key ?

You can't as they are incompatible structures. However you can *use* a private
key anywhere you'd use a public key because the private key contains all the
public key components.

> And are the any way to get human understandable error message ?
> 

Read the FAQ.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Homepage: http://www.drh-consultancy.demon.co.uk
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-13 Thread Th�nh Trung Nguyễn
Hi shankar,
Thanks you for your answer !

You said " we can not get public key from a private key ".
Then you said "So PEM_read_RSAPublicKey() or PEM_read_RSA_PUBKEY() can be used 
to load public key from a private key"

I'm being confused. Did you mean we those 2 functions can not be use to load 
public key from a private key ?

In fact, i don't try to get public key from private key, but may be the users 
will. So I want to have a right answer for that. I'm still new with 
cryptography and this library so I don't know if I'm right or wrong.

shankar ks <[EMAIL PROTECTED]> wrote: Hi Trung,
  
 One thing I will conform you is " we can not get public key from a private key 
". I do not remember where i studied , but it is true.
 So do not try to get a public key from private key.
 And I have mistakenly typed as BEGIN RSA CERTIFICATE , as you told it is BEGIN 
RSA PUBLIC KEY only.
  
 So PEM_read_RSAPublicKey() or PEM_read_RSA_PUBKEY() can be used to load public 
key from a private key
  
 The main concept (and also the general concept )in my program ( or any other 
programs )is we have to load public key from the certificate only . 
 In the certificte if the public key does not have header like  BEGIN RSA 
PUBLIC KEY , then these functions wont work . so I have used other procedure to 
get the RSA public key ..
  
 if you still have doubts , mail me ...
  
 --- Shankar
  
 

 
 On 4/13/08, Thành Trung Nguyễn <[EMAIL PROTECTED]> wrote: Thank you for 
fast response !

But it's ok if I use PEM_read_RSAPublicKey() to load public key from file save 
by using PEM_write_RSAPublicKey().
 And even publickey extract by openssl command doesn't have any line as "BEGIN 
RSA CERTIFICATE". It just has line as "BEGIN RSA PUBLIC KEY".

I've tried your code, but it can't read public key save by openssl.
 
So can PEM_read_RSAPublicKey() or PEM_read_RSA_PUBKEY() can load public key 
from a private key ? In my program, I use PEM_write_RSAPublicKey() to store 
public key and use PEM_read_RSAPublicKey() to load it. I just want to know if 
user can use my program to read public key from a private key.
 
p/s :
I used openssl to extract publickey like this ( I don't know if there is 
another way) :
openssl rsa -in privatekey.pem -out publickey.pem -pubout


shankar ks <[EMAIL PROTECTED]> wrote:   Hi Trung,
  The error which u got was you can not read the public key as in the 
certificate it is not finding the lines as "BEGIN RSA CERTIFICATE"
 so here i am giving you the code , use it directly , it will work fine as i 
refined it many times ... and one more thing is error string funtion will give 
you the reason also , so it is human readible message only...
   
  
 pubk = RSA_new();
if(pubk == NULL)
printf("error to create new RSA structure \n");
 fp = fopen (recevercert, "r");
if (fp == NULL){
pri ntf("err ");
exit (1);
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
fclose (fp);
 
if (x509 == NULL) {
printf("error reading the certificate \n");
ERR_print_errors_fp (stderr);
exit (1);
}
 pub=X509_get_pubkey(x509);
if (pub == NULL) {
printf("error reading the public key \n");
ERR_print_errors_fp (stderr);
exit (1);
}
 pubk = EVP_PKEY_get1_RSA(pub);
 


 
 On 4/13/08, Th�nh Trung Nguyễn <[EMAIL PROTECTED]> wrote:  Hi !

I used PEM_write_RSAPrivateKey() to write private key to a pem file.
Then I used PEM_read_RSAPublicKey() to read public key from that file, but it 
returned an error.
 The ERR_error_string() only return message like :
error:0906D06C:lib(9):func(109):reason(108)
So can any one tell me can i use PEM_read_RSAPublicKey() to load public key 
from a private key ?
And are the any way to get human understandable error message ?
 
Thanks !


trungnt  __
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
 



-- 
--Best Regards
Shankar  


trungnt  __
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
 




-- 
--Best Regards
Shankar  


trungnt
 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-12 Thread shankar ks
Hi Trung,

One thing I will conform you is " we can not get public key from a private
key ". I do not remember where i studied , but it is true.
So do not try to get a public key from private key.
And I have mistakenly typed as BEGIN RSA CERTIFICATE , as you told it is
BEGIN RSA PUBLIC KEY only.

So PEM_read_RSAPublicKey() or PEM_read_RSA_PUBKEY() can be used to load
public key from a private key

The main concept (and also the general concept )in my program ( or any other
programs )is we have to load public key from the certificate only .
In the certificte if the public key does not have header like  BEGIN RSA
PUBLIC KEY , then these functions wont work . so I have used other procedure
to get the RSA public key ..

if you still have doubts , mail me ...

--- Shankar




On 4/13/08, Thành Trung Nguyễn <[EMAIL PROTECTED]> wrote:
>
> Thank you for fast response !
>
> But it's ok if I use PEM_read_RSAPublicKey() to load public key from file
> save by using PEM_write_RSAPublicKey().
> And even publickey extract by openssl command doesn't have any line as
> "BEGIN RSA CERTIFICATE". It just has line as "BEGIN RSA PUBLIC KEY".
>
> I've tried your code, but it can't read public key save by openssl.
>
> So can PEM_read_RSAPublicKey() or PEM_read_RSA_PUBKEY() can load public
> key from a private key ? In my program, I use PEM_write_RSAPublicKey() to
> store public key and use PEM_read_RSAPublicKey() to load it. I just want to
> know if user can use my program to read public key from a private key.
>
> p/s :
> I used openssl to extract publickey like this ( I don't know if there
> is another way) :
> openssl rsa -in privatekey.pem -out publickey.pem -pubout
>
>
> *shankar ks <[EMAIL PROTECTED]>* wrote:
>
> Hi Trung,
>  The error which u got was you can not read the public key as in the
> certificate it is not finding the lines as "BEGIN RSA CERTIFICATE"
> so here i am giving you the code , use it directly , it will work fine as
> i refined it many times ... and one more thing is error string funtion will
> give you the reason also , so it is human readible message only...
>
>
> pubk = RSA_new();
> if(pubk == NULL)
> printf("error to create new RSA structure \n");
> fp = fopen (recevercert, "r");
> if (fp == NULL){
> pri ntf("err ");
> exit (1);
> }
> x509 = PEM_read_X509(fp, NULL, NULL, NULL);
> fclose (fp);
>
> if (x509 == NULL) {
> printf("error reading the certificate \n");
> ERR_print_errors_fp (stderr);
> exit (1);
> }
> pub=X509_get_pubkey(x509);
> if (pub == NULL) {
> printf("error reading the public key \n");
> ERR_print_errors_fp (stderr);
> exit (1);
> }
> pubk = EVP_PKEY_get1_RSA(pub);
>
>
>
>
> On 4/13/08, Th�nh Trung Nguyễn <[EMAIL PROTECTED]> wrote:
> >
> > Hi !
> >
> > I used PEM_write_RSAPrivateKey() to write private key to a pem file.
> > Then I used PEM_read_RSAPublicKey() to read public key from that file,
> > but it returned an error.
> > The ERR_error_string() only return message like :
> > error:0906D06C:lib(9):func(109):reason(108)
> > So can any one tell me can i use PEM_read_RSAPublicKey() to load public
> > key from a private key ?
> > And are the any way to get human understandable error message ?
> >
> > Thanks !
> >
> >
> > trungnt __
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
>
>
> --
> --Best Regards
> Shankar
>
>
>
>
> trungnt
>
> __
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



-- 
--Best Regards
Shankar


Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-12 Thread Th�nh Trung Nguyễn
Thank you for fast response !

But it's ok if I use PEM_read_RSAPublicKey() to load public key from file save 
by using PEM_write_RSAPublicKey().
And even publickey extract by openssl command doesn't have any line as "BEGIN 
RSA CERTIFICATE". It just has line as "BEGIN RSA PUBLIC KEY".

I've tried your code, but it can't read public key save by openssl.

So can PEM_read_RSAPublicKey() or PEM_read_RSA_PUBKEY() can load public key 
from a private key ? In my program, I use PEM_write_RSAPublicKey() to store 
public key and use PEM_read_RSAPublicKey() to load it. I just want to know if 
user can use my program to read public key from a private key.

p/s :
I used openssl to extract publickey like this ( I don't know if there is 
another way) :
openssl rsa -in privatekey.pem -out publickey.pem -pubout


shankar ks <[EMAIL PROTECTED]> wrote: Hi Trung,
  The error which u got was you can not read the public key as in the 
certificate it is not finding the lines as "BEGIN RSA CERTIFICATE"
 so here i am giving you the code , use it directly , it will work fine as i 
refined it many times ... and one more thing is error string funtion will give 
you the reason also , so it is human readible message only...
   
  
 pubk = RSA_new();
if(pubk == NULL)
printf("error to create new RSA structure \n");
 fp = fopen (recevercert, "r");
if (fp == NULL){
pri ntf("err ");
exit (1);
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
fclose (fp);
  
if (x509 == NULL) {
printf("error reading the certificate \n");
ERR_print_errors_fp (stderr);
exit (1);
}
 pub=X509_get_pubkey(x509);
if (pub == NULL) {
printf("error reading the public key \n");
ERR_print_errors_fp (stderr);
exit (1);
}
 pubk = EVP_PKEY_get1_RSA(pub);




 On 4/13/08, Th�nh Trung Nguyễn <[EMAIL PROTECTED]> wrote: Hi !

I used PEM_write_RSAPrivateKey() to write private key to a pem file.
Then I used PEM_read_RSAPublicKey() to read public key from that file, but it 
returned an error.
 The ERR_error_string() only return message like :
error:0906D06C:lib(9):func(109):reason(108)
So can any one tell me can i use PEM_read_RSAPublicKey() to load public key 
from a private key ?
And are the any way to get human understandable error message ?
 
Thanks !


trungnt  __
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
 



-- 
--Best Regards
Shankar  


trungnt
 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-12 Thread shankar ks
Hi Trung,
 The error which u got was you can not read the public key as in the
certificate it is not finding the lines as "BEGIN RSA CERTIFICATE"
so here i am giving you the code , use it directly , it will work fine as i
refined it many times ... and one more thing is error string funtion will
give you the reason also , so it is human readible message only...



pubk = RSA_new();
if(pubk == NULL)
printf("error to create new RSA structure \n");

fp = fopen (recevercert, "r");
if (fp == NULL){
pri ntf("err ");
exit (1);
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
fclose (fp);


if (x509 == NULL) {
printf("error reading the certificate \n");
ERR_print_errors_fp (stderr);
exit (1);
}

pub=X509_get_pubkey(x509);
if (pub == NULL) {
printf("error reading the public key \n");
ERR_print_errors_fp (stderr);
exit (1);
}

pubk = EVP_PKEY_get1_RSA(pub);


On 4/13/08, Thành Trung Nguyễn <[EMAIL PROTECTED]> wrote:
>
> Hi !
>
> I used PEM_write_RSAPrivateKey() to write private key to a pem file.
> Then I used PEM_read_RSAPublicKey() to read public key from that file, but
> it returned an error.
> The ERR_error_string() only return message like :
> error:0906D06C:lib(9):func(109):reason(108)
> So can any one tell me can i use PEM_read_RSAPublicKey() to load public
> key from a private key ?
> And are the any way to get human understandable error message ?
>
> Thanks !
>
>
> trungnt
>
> __
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



-- 
--Best Regards
Shankar


Can PEM_read_RSAPublicKey() load public key from private key ?

2008-04-12 Thread Th�nh Trung Nguyễn
Hi !

I used PEM_write_RSAPrivateKey() to write private key to a pem file.
Then I used PEM_read_RSAPublicKey() to read public key from that file, but it 
returned an error.
The ERR_error_string() only return message like :
error:0906D06C:lib(9):func(109):reason(108)
So can any one tell me can i use PEM_read_RSAPublicKey() to load public key 
from a private key ?
And are the any way to get human understandable error message ?

Thanks !


trungnt
 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: PEM_read_RSAPublicKey

2001-12-26 Thread Ricardo Guerra

thanks :)
pubKey is supposed to be used to decrypt a string previously encrypted with 
the privateKey (rsa_private_encrypt)..

by the way... is it possible? i have seen some code and openssl itself to 
encrypt using public key and decrypt using the private key... 

El Miércoles 26 Diciembre 2001 19:09, escribiste:
> Ricardo Guerra wrote:
> > hi all,
> >
> > i've been having trouble with this pice of code, i get a segmentation
> > fault when reading the public key, this is the way i generated both
> > private and public keys.
> >
> > priv Key: openssl genrsa -out priv.key 1024
> > pub Key: cat pub.key | openssl rsa -pubout > pub.key
> >
> > does anyone have any idea about what does this happen?
> >
> > i'm using rh linux 6.2 with openssl 0.9.6b 9
> >
> > int FOROLicense::LoadPublicKey (char *name)
> > {
> >FILE *file;
> >if ((file=fopen(name, "rb"))== NULL)
> >  return 0;
> >
> >pubKey=*PEM_read_RSAPublicKey(file, NULL, NULL, NULL);
> >
> >fclose (file);
> >loadedPub=1;
> >return loadedPub;
> > }
>
> Not sure what the pubkey stuff is supposed to be doing. pubKey should be
> declared somewhere as:
>
> RSA *pubKey;
>
> then call:
>
> pubKey = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL);
>
> (not RSAPublicKey).
>
> Steve.
--
This email is confidential and intended solely for the use of the individual to whom 
it is addressed. Any views or opinions presented are solely those of the author and do 
not necessarily represent those of SchlumbergerSema. 
If you are not the intended recipient, be advised that you have received this email in 
error and that any use, dissemination, forwarding, printing, or copying of this email 
is strictly prohibited.
--

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



Re: PEM_read_RSAPublicKey

2001-12-26 Thread Dr S N Henson

Ricardo Guerra wrote:
> 
> hi all,
> 
> i've been having trouble with this pice of code, i get a segmentation fault
> when reading the public key, this is the way i generated both private and
> public keys.
> 
> priv Key: openssl genrsa -out priv.key 1024
> pub Key: cat pub.key | openssl rsa -pubout > pub.key
> 
> does anyone have any idea about what does this happen?
> 
> i'm using rh linux 6.2 with openssl 0.9.6b 9
> 
> int FOROLicense::LoadPublicKey (char *name)
> {
>FILE *file;
>if ((file=fopen(name, "rb"))== NULL)
>  return 0;
> 
>pubKey=*PEM_read_RSAPublicKey(file, NULL, NULL, NULL);
> 
>fclose (file);
>loadedPub=1;
>return loadedPub;
> }

Not sure what the pubkey stuff is supposed to be doing. pubKey should be
declared somewhere as:

RSA *pubKey;

then call:

pubKey = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL);

(not RSAPublicKey).

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]



PEM_read_RSAPublicKey

2001-12-26 Thread Ricardo Guerra

hi all,

i've been having trouble with this pice of code, i get a segmentation fault 
when reading the public key, this is the way i generated both private and 
public keys.

priv Key: openssl genrsa -out priv.key 1024
pub Key: cat pub.key | openssl rsa -pubout > pub.key

does anyone have any idea about what does this happen?

i'm using rh linux 6.2 with openssl 0.9.6b 9 





int FOROLicense::LoadPublicKey (char *name)
{
   FILE *file;
   if ((file=fopen(name, "rb"))== NULL)
 return 0;

   pubKey=*PEM_read_RSAPublicKey(file, NULL, NULL, NULL);

   fclose (file);
   loadedPub=1;
   return loadedPub;
}
--
This email is confidential and intended solely for the use of the individual to whom 
it is addressed. Any views or opinions presented are solely those of the author and do 
not necessarily represent those of SchlumbergerSema. 
If you are not the intended recipient, be advised that you have received this email in 
error and that any use, dissemination, forwarding, printing, or copying of this email 
is strictly prohibited.
--

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



Re: PEM_read_RSAPublicKey

2001-11-16 Thread Juan Segarra

On Fri, 16 Nov 2001, Takaaki Ishii wrote:

> Hylton Tregenza wrote:
> >Sorry, I asked to early, There is nothing wrong with the code. The file
> >is not a public key file (or the format isd wrong) How do I extract a
> >public key file from a certificate?
>
>   How about to use  X509_get_pubkey function?
>

Perhaps demos/sign/sign.c will be useful...

Juan.

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



Re: PEM_read_RSAPublicKey

2001-11-16 Thread Takaaki Ishii

Hylton Tregenza wrote:
>Sorry, I asked to early, There is nothing wrong with the code. The file
>is not a public key file (or the format isd wrong) How do I extract a
>public key file from a certificate?

by command line:
$ openssl x509 -in cert.pem -pubkey -noout

by writing some code:
How about to use  X509_get_pubkey function?

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
from Fukuoka.Japan
__
OpenSSL Project http://www.openssl.org
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager   [EMAIL PROTECTED]



RE: PEM_read_RSAPublicKey

2001-11-16 Thread Hylton Tregenza



Sorry, I asked to early, There is 
nothing wrong with the code. The file is not a public key file (or the format 
isd wrong) How do I extract a public key file from a 
certificate?
Hylton

  -Original Message-From: Hylton Tregenza 
  Sent: 16 November 2001 12:24To: 
  [EMAIL PROTECTED]Subject: 
  PEM_read_RSAPublicKey
  Hi 
  I am trying to read a public key from a certificate 
  file in PEM format. My code looks as 
  follows. I constanty get null as a result 
  from the call to PEM_read_RSAPublicKey 
  #include  #include  #include  #include  #include  #include  #include  
  #include "main.h" 
  #define HOME    
  "/home/hetregenza/projects/ssl_cert/" //#define HOME  "./" 
  #define CLIENTCERTF HOME 
  "clientcert.pem" #define 
  CLIENTKEYF  HOME "clientkey.pem" #define SERVERCERTF HOME 
  "servercert.pem" #define 
  SERVERKEYF  HOME "serverkey.pem" #define CASERVCERTF HOME 
  "cacert.pem" 
  int main(int argc, char ** argv) 
      
      {     void * pUser; 
      char 
  szUser[2000];     EVP_PKEY * pEVP_PKEY = 0; 
      EVP_PKEY ** ppEVP_PKEY = 0; 
      BIO_METHOD * pBIO_METHOD; 
      BIO * 
    pBIO = 0;     RSA *   pRSA = 0; 
      RSA 
  **  ppRSA = 0; 
      pBIO_METHOD = BIO_s_file(); 
      memset 
  (&szUser, 0, sizeof(szUser)); 
      pBIO = 
  BIO_new_file(CLIENTCERTF, "r"); 
      pRSA = 
  PEM_read_bio_RSAPublicKey(pBIO, ppRSA, PasswdCallback, (void *)szUser); // get 
  null back here. 
   
  BIO_free(pBIO);     
      return 
  0;     } 
  The code does not even get to the call back 
  function. Any assistance appreciated 
  
  Hylton 


smime.p7s
Description: application/pkcs7-signature


PEM_read_RSAPublicKey

2001-11-16 Thread Hylton Tregenza





Hi


I am trying to read a public key from a certificate file in PEM format. 

My code looks as follows.

I constanty get null as a result from the call to PEM_read_RSAPublicKey


#include 

#include 

#include 

#include 

#include 

#include 

#include 


#include "main.h"


#define HOME    "/home/hetregenza/projects/ssl_cert/"

//#define HOME  "./"


#define CLIENTCERTF HOME "clientcert.pem"

#define CLIENTKEYF  HOME "clientkey.pem"

#define SERVERCERTF HOME "servercert.pem"

#define SERVERKEYF  HOME "serverkey.pem"

#define CASERVCERTF HOME "cacert.pem"



int main(int argc, char ** argv)

    

    {

    void * pUser;

    char szUser[2000];

    EVP_PKEY * pEVP_PKEY = 0;

    EVP_PKEY ** ppEVP_PKEY = 0;

    BIO_METHOD * pBIO_METHOD;


    BIO *   pBIO = 0;

    RSA *   pRSA = 0;

    RSA **  ppRSA = 0;


    pBIO_METHOD = BIO_s_file();

    memset (&szUser, 0, sizeof(szUser));


    pBIO = BIO_new_file(CLIENTCERTF, "r");

    pRSA = PEM_read_bio_RSAPublicKey(pBIO, ppRSA, PasswdCallback, (void *)szUser); // get null back here.


 BIO_free(pBIO);

    

    return 0;

    }


The code does not even get to the call back function.

Any assistance appreciated


Hylton





smime.p7s
Description: application/pkcs7-signature


Re: pem_read_rsapublickey question

2001-10-01 Thread Dr S N Henson

d p chang wrote:
> 
> Checking the user archives I haven't seen anyone address this sort of
> problem (v0.9.6b). 

Well it has been addressed before...

> I've generated the various keys w/ something liek
> this (from teh man page)
> 
> openssl genrsa -out priv.pem 1024
> openssl rsa -in priv.pem -pubout -out pub.pem
> 
> However, when trying to read in the public key w/
> pem_read_rsapublickey I get a pem_read_bio:'no start line' error. The
> public key file only has (-BEGIN PUBLIC KEY-) while the
> private key file has (-BEGIN RSA PRIVATE KEY-). Checking the
> source, the 'workaround' seems obvious...
> 

The actual header lines, in many (but not all) cases give an indication
of the type of data enclosed inside. So just changing them without
changing the enclosed data wont necessarily work.

> However, when I hand edit the public key file by adding the type (RSA)
> i get a new error:
> 
> lib(13 : asn1 encoding routines)
> func(280 : d2i_ASN1_UINTEGER)
> reason(113 : expecting an integer)
> 
> which is less clear how to 'fix' since I haven't dug around the
> internals too much.
> 

This error is due to the incompatibility in the enclosed data. Once is
an encoded PublicKeyInfo, the other an RSAPublicKey structure.

> Anyway, my questions are:
> 
> 1 - is this the right way to be going about this?
> 2 - is there some other incantation that I'm missing when
> generating the keys?
> 

All you're missing is that your reading in the public key using the
wrong function. You should use PEM_read_RSA_PUBKEY instead.

Steve.
-- 
Dr Stephen N. Henson.   http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED] 
Senior crypto engineer, Celo Communications: http://www.celocom.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]



pem_read_rsapublickey question

2001-10-01 Thread d p chang

[ sorry, if this goes through twice, i had a typo in my first to line ]

Checking the user archives I haven't seen anyone address this sort of
problem (v0.9.6b). I've generated the various keys w/ something liek
this (from teh man page)

openssl genrsa -out priv.pem 1024
openssl rsa -in priv.pem -pubout -out pub.pem

However, when trying to read in the public key w/
pem_read_rsapublickey I get a pem_read_bio:'no start line' error. The
public key file only has (-BEGIN PUBLIC KEY-) while the
private key file has (-BEGIN RSA PRIVATE KEY-). Checking the
source, the 'workaround' seems obvious...

However, when I hand edit the public key file by adding the type (RSA)
i get a new error:

lib(13 : asn1 encoding routines) 
func(280 : d2i_ASN1_UINTEGER)
reason(113 : expecting an integer)

which is less clear how to 'fix' since I haven't dug around the
internals too much. 

Anyway, my questions are:

1 - is this the right way to be going about this?
2 - is there some other incantation that I'm missing when
generating the keys?

\p
---
God forbid that any books should be banned.  The practice is as
indefensible as infanticide. --- Dame Rebecca West

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



pem_read_rsapublickey question

2001-10-01 Thread d p chang


Checking the user archives I haven't seen anyone address this sort of
problem (v0.9.6b). I've generated the various keys w/ something liek
this (from teh man page)

openssl genrsa -out priv.pem 1024
openssl rsa -in priv.pem -pubout -out pub.pem

However, when trying to read in the public key w/
pem_read_rsapublickey I get a pem_read_bio:'no start line' error. The
public key file only has (-BEGIN PUBLIC KEY-) while the
private key file has (-BEGIN RSA PRIVATE KEY-). Checking the
source, the 'workaround' seems obvious...

However, when I hand edit the public key file by adding the type (RSA)
i get a new error:

lib(13 : asn1 encoding routines) 
func(280 : d2i_ASN1_UINTEGER)
reason(113 : expecting an integer)

which is less clear how to 'fix' since I haven't dug around the
internals too much. 

Anyway, my questions are:

1 - is this the right way to be going about this?
2 - is there some other incantation that I'm missing when
generating the keys?

\p
---
You live and learn. At any rate, you live. --- Douglas Adams

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