> From: [email protected] On Behalf Of engineereeyore
> Sent: Monday, 17 December, 2012 15:52

> Anyone have any ideas?  Still haven't found a solution.

> View this message in context: 
> http://openssl.6102.n7.nabble.com/Problem-reading-public-key-f
> rom-PEM-tp42657p42794.html
> Sent from the OpenSSL - User mailing list archive at Nabble.com.

I didn't see the original message, and that webpage says 
"This post has NOT been accepted by the mailing list yet. "
(on a yellow bar, no less, at least on my IE).

PEM_write_[bio_]RSA_PrivateKey writes a privatekey blob.
You cannot use read*PUBKEY on a privatekey blob.

The OpenSSL RSA key structure for a generated keypair 
(and most but not all other cases) actually contains the 
publickey info embedded. The read/write pubkey routines 
operate on the publickey components and ignore the rest.
If you want the two "halves" separately -- e.g. the usual case 
keep your privatekey to yourself and publish your publickey -- 
just do RSA_generate_key, then PEM_write*_RSAPrivateKey, 
then PEM_write*_RSA_PUBKEY >on the same RSA structure<.
(Or similarly i2d*PrivateKey and i2d*PUBKEY for DER format.)

You can have multiple different-type PEM blobs in one >file< 
if you want, because the read routines find the correct one 
by matching the "BEGIN" line. However, you probably don't want 
to put your pubkey and privkey in the same file, so use two 
different files. Or write both to one file and then split it 
with any text editor or text tool like sed/gawk/perl/etc.

If you read through apps/rsa.c as you said you should see this.
It can read *either* a privkey or a pubkey but for the latter 
you must specify -pubin; and if you have read a privkey it can 
write either the same privkey or the subsetted pubkey if -pubin, 
but if you read a pubkey it can only write pubkey.

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

Reply via email to