# Public\_key in X509 format?

**URL:** <https://www.ruby-forum.com/t/public-key-in-x509-format/68258>\
**Category:** Ruby\
**Created:** [September 11, 2006, 7:57am UTC](https://www.ruby-forum.com/t/public-key-in-x509-format/68258 "2006-09-11T07:57:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phudson1442](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@phudson1442](https://www.ruby-forum.com/u/phudson1442)\
**Post date:** [September 11, 2006, 7:57am UTC](https://www.ruby-forum.com/t/public-key-in-x509-format/68258/1 "2006-09-11T07:57:22Z")

</div>

Hi All,

Is there any way to get an RSA public key in X509 format? By default  
RSA pub keys are dumped out in PKCS#1 format but I really need X509.  
I know that the C call that’s being used to create the public key is  
PEM\_write\_bio\_RSAPublicKey and I don’t see any reference to  
PEM\_write\_bio\_PUBKEY, so I’m guessing somehow converting from one to  
the other is my only choice.

So is there some way to use the current APIs to convert from that  
PKCS#1 format to X509?

---

<div class="post-metadata">

**Author:** ![phudson1442](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@phudson1442](https://www.ruby-forum.com/u/phudson1442)\
**Post date:** [September 11, 2006, 8:27am UTC](https://www.ruby-forum.com/t/public-key-in-x509-format/68258/2 "2006-09-11T08:27:24Z")

</div>

> So is there some way to use the current APIs to convert from that  
> PKCS#1 format to X509?

X509 is the structure used for certificates that contains the  
identifying information about the certificate along with the public  
key. There is no such thing as a public key in X509 format.  
Sometimes people refer to certificates as public key certificates,  
because the certificate always has a public key component.

Chris

---

<div class="post-metadata">

**Author:** ![phudson1442](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@phudson1442](https://www.ruby-forum.com/u/phudson1442)\
**Post date:** [September 11, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/public-key-in-x509-format/68258/3 "2006-09-11T15:58:16Z")

</div>

Chris,

On 9/11/06, snacktime [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> X509 is the structure used for certificates that contains the  
> identifying information about the certificate along with the public  
> key. There is no such thing as a public key in X509 format.  
> Sometimes people refer to certificates as public key certificates,  
> because the certificate always has a public key component.  
> I guess I used the wrong terminology I meant the key in X509  
> SubjectPublicKeyInfo, or to be more precise the one that has

-----BEGIN PUBLIC KEY-----

at the top.

---

<div class="post-metadata">

**Author:** ![phudson1442](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@phudson1442](https://www.ruby-forum.com/u/phudson1442)\
**Post date:** [September 11, 2006, 9:37am UTC](https://www.ruby-forum.com/t/public-key-in-x509-format/68258/4 "2006-09-11T09:37:31Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi,

Paul H. wrote:

> So is there some way to use the current APIs to convert from that  
> PKCS#1 format to X509?

ASN.1 DER + base64?

0% ruby -ropenssl -e  
‘OpenSSL::PKey::RSA.new(1024).public\_key.to\_pem.display’

- -----BEGIN RSA PUBLIC KEY-----  
MIGJAoGBAL8KLG/KSWzi48EMsa6cNlWwXKIrDUjn3dsoWv5fF31J/PUkg0ULw45I  
kBapGw+9iUcfUIOegY80d+WDTO56F0OhLNA4+0huAPfcdVASDnbhyYTn8mQgv2Rf  
qUEvL5+bnacbmN0NVhg9PhljZci2hEFsUDcJP2OX+pbcmXfvnVjbAgMBAAE=
- -----END RSA PUBLIC KEY-----

You may be interested in PKCS#1 encoder in [http://dev.ctor.org/pkcs1](http://dev.ctor.org/pkcs1)

Regards,  
// NaHi  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2.1 (Cygwin)

iQEVAwUBRQUR6R9L2jg5EEGlAQK9RwgAyEeJT1Ku2f4XgfXW/mRcRYQwO0E0o/6A  
vV15k0Ycrv9aO6LEcV3dfb9fCQOe67le+/O8THEVRmCFX8DaIAYSLzM3ketr9I8B  
u0qeRbcPe4S1eO1ZfhBo/872WRRaZXwcZsCxYKnqtleEp9SgQinWn7NbTWE5nVE9  
yEB7PFxM9rLBCH7W860ZI/hT3FZWnR94XgUSLudEWU5DI4sJaLV24ssDyDM0jgj5  
BFzCIg2s960hwkz/3kis+SdLgLePzXB/k60I8RaieaKyPdXbsVh4wSRgtL6QSXEY  
UT3RDLmKPzwll8aPUgFHGkH/ZGXPEEi6X1QfMA0f3Iz6wDDJUspgpQ==  
=p6Up  
-----END PGP SIGNATURE-----
