From RSA to string and compare problem
Hi,
i'm creating a little client/server program using C. i need to read a
rsa from pem file (so using PEM_read_RSAPublicKey) and then send the
key to a server (the message can be only a string type) which reads a
rsa public key from another pem file and return, comparing keys, is are
egual or not.
Can someone plz help me to understand if into the library already exist
a way to convert the struct RSA into 1-line string and viceversa ?
Which is the correct way to compare 2 keys ? Again, there are in library
some ad-hoc function ?
TNX A LOT
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]
Re: From RSA to string and compare problem
Hello,
[email]owner-openssl-users@openssl.org[/email] wrote on 06/25/2008 04:10:45 PM:
[color=blue]
> Hi,
> i'm creating a little client/server program using C. i need to read a
> rsa from pem file (so using PEM_read_RSAPublicKey) and then send the
> key to a server (the message can be only a string type) which reads a
> rsa public key from another pem file and return, comparing keys, is are
> egual or not.[/color]
What about just reading your .pem file with simple read() to char table
and send this to server ?
Best regards,
--
Marek Marcola <Marek.Marcola@malkom.pl>
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]
Re: From RSA to string and compare problem
[email]Marek.Marcola@malkom.pl[/email] ha scritto:[color=blue]
> Hello,
>
> [email]owner-openssl-users@openssl.org[/email] wrote on 06/25/2008 04:10:45 PM:
>
>[color=green]
>> Hi,
>> i'm creating a little client/server program using C. i need to read a
>> rsa from pem file (so using PEM_read_RSAPublicKey) and then send the
>> key to a server (the message can be only a string type) which reads a
>> rsa public key from another pem file and return, comparing keys, is are
>> egual or not.
>>[/color]
> What about just reading your .pem file with simple read() to char table
> and send this to server ?
>
> Best regards,
> --
> Marek Marcola <Marek.Marcola@malkom.pl>
>
> ______________________________________________________________________
> OpenSSL Project [url]http://www.openssl.org[/url]
> User Support Mailing List [email]openssl-users@openssl.org[/email]
> Automated List Manager [email]majordomo@openssl.org[/email]
>[/color]
Yes of course. But nothing more elegant ?
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]
Re: From RSA to string and compare problem
Hello,
[email]owner-openssl-users@openssl.org[/email] wrote on 06/25/2008 04:34:07 PM:
[color=blue]
> [email]Marek.Marcola@malkom.pl[/email] ha scritto:[color=green]
> > Hello,
> >
> > [email]owner-openssl-users@openssl.org[/email] wrote on 06/25/2008 04:10:45 PM:
> >
> >[color=darkred]
> >> Hi,
> >> i'm creating a little client/server program using C. i need to read a[/color][/color][/color]
[color=blue][color=green][color=darkred]
> >> rsa from pem file (so using PEM_read_RSAPublicKey) and then send the[/color][/color][/color]
[color=blue][color=green][color=darkred]
> >> key to a server (the message can be only a string type) which reads a[/color][/color][/color]
[color=blue][color=green][color=darkred]
> >> rsa public key from another pem file and return, comparing keys, is[/color][/color][/color]
are[color=blue][color=green][color=darkred]
> >> egual or not.
> >>[/color]
> > What about just reading your .pem file with simple read() to char[/color][/color]
table[color=blue][color=green]
> > and send this to server ?
> >
> > Best regards,
> > --
> > Marek Marcola <Marek.Marcola@malkom.pl>
> >
> > ______________________________________________________________________
> > OpenSSL Project [url]http://www.openssl.org[/url]
> > User Support Mailing List [email]openssl-users@openssl.org[/email]
> > Automated List Manager [email]majordomo@openssl.org[/email]
> >[/color]
> Yes of course. But nothing more elegant ?[/color]
I do not think that in this case are more elegant solutions ...
..... but you can try:
You may create memory BIO:
BIO *mem;
if ((mem = BIO_new(BIO_s_mem())) == NULL) {
goto err;
}
Write public key to this bio:
if (PEM_write_bio_PUBKEY(mem, key) == 0) {
BIO_free(mem);
goto err;
}
and read to buffer in PEM format:
if ((n = BIO_read(mem, buf, *len)) <= 0) {
BIO_free(mem);
goto err;
}
BIO_free(mem);
This code is not tested nor checked, hope this helps.
Best regards,
--
Marek Marcola <Marek.Marcola@malkom.pl>
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]
R: From RSA to string and compare problem
Tnx for response and your patient.
Returning on reading with read() may I ask you about comment header and
footer? It's safe to jump lines of file pem starting with "-" or it's
possible that the key contain the char "-" ?
tnx
-----Messaggio originale-----
Da: [email]owner-openssl-users@openssl.org[/email] [mailto:owner-openssl-users@openssl.org]
Per conto di [email]Marek.Marcola@malkom.pl[/email]
Inviato: giovedì 26 giugno 2008 0.57
A: [email]openssl-users@openssl.org[/email]
Oggetto: Re: From RSA to string and compare problem
Hello,
[email]owner-openssl-users@openssl.org[/email] wrote on 06/25/2008 04:34:07 PM:
[color=blue]
> [email]Marek.Marcola@malkom.pl[/email] ha scritto:[color=green]
> > Hello,
> >
> > [email]owner-openssl-users@openssl.org[/email] wrote on 06/25/2008 04:10:45 PM:
> >
> > [color=darkred]
> >> Hi,
> >> i'm creating a little client/server program using C. i need to read a [/color][/color][/color]
[color=blue][color=green][color=darkred]
> >> rsa from pem file (so using PEM_read_RSAPublicKey) and then send the [/color][/color][/color]
[color=blue][color=green][color=darkred]
> >> key to a server (the message can be only a string type) which reads a [/color][/color][/color]
[color=blue][color=green][color=darkred]
> >> rsa public key from another pem file and return, comparing keys, is [/color][/color][/color]
are [color=blue][color=green][color=darkred]
> >> egual or not.
> >> [/color]
> > What about just reading your .pem file with simple read() to char [/color][/color]
table[color=blue][color=green]
> > and send this to server ?
> >
> > Best regards,
> > --
> > Marek Marcola <Marek.Marcola@malkom.pl>
> >
> > ______________________________________________________________________
> > OpenSSL Project [url]http://www.openssl.org[/url]
> > User Support Mailing List [email]openssl-users@openssl.org[/email]
> > Automated List Manager [email]majordomo@openssl.org[/email]
> > [/color]
> Yes of course. But nothing more elegant ?[/color]
I do not think that in this case are more elegant solutions ...
..... but you can try:
You may create memory BIO:
BIO *mem;
if ((mem = BIO_new(BIO_s_mem())) == NULL) {
goto err;
}
Write public key to this bio:
if (PEM_write_bio_PUBKEY(mem, key) == 0) {
BIO_free(mem);
goto err;
}
and read to buffer in PEM format:
if ((n = BIO_read(mem, buf, *len)) <= 0) {
BIO_free(mem);
goto err;
}
BIO_free(mem);
This code is not tested nor checked, hope this helps.
Best regards,
--
Marek Marcola <Marek.Marcola@malkom.pl>
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]
Re: R: From RSA to string and compare problem
Hello,
[email]owner-openssl-users@openssl.org[/email] wrote on 06/26/2008 02:06:47 AM:
[color=blue]
> Returning on reading with read() may I ask you about comment header and
> footer? It's safe to jump lines of file pem starting with "-" or it's
> possible that the key contain the char "-" ?[/color]
Data between BEGIN and END header is ASN1 structure encoded with base64.
Base64 encoded data can have the following characters:
static const char base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789"
"+/"
(and '=' as padding character if required - only at end of data)
As you see, there can not be '-' character inside base64 encoded data.
Best regards,
--
Marek Marcola <Marek.Marcola@malkom.pl>
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]