Re: [Botan-devel] How can extract public key from x509Cert
Brought to you by:
randombit
|
From: Jack L. <ll...@ac...> - 2003-07-20 20:14:17
|
On Sun, 20 Jul 2003, Marcus Meyer wrote:
> Hallo,
> I have a list of many X509Cert. The X509Cert Object can successful read
> the certificate und show me the infos (subject_dn issure_dn ...). The
> Problem is, it can not extract the public key object from the
> certificate.
That is bad.
> Botan::X509_PublicKey* key( Botan::X509::load_key("test.cert") );
> rise the exeption "X.509 public key decoding failed"
This will always fail, because the certificate has a bunch of other things
besides the public key, but load_key doesn't know that.
> the same exeption is come when I use the
> X509Certificate.subject_public_key().
This should not happen.
> I can extract the publickey with "openssl x509 -in cert -pubkey
> then i can create my X509Pubkey object.
>
> Have anybody a idea how i can do this without using openssl?
The following program reads the public key from your sample certificate
just fine (at least with 1.2.4, which is the only version I have built on
this machine). What it prints matches what I get from running
'openssl x509 -in somecert.pem -pubkey -noout'
---- CUT ----
#include <botan/x509cert.h>
using namespace Botan;
#include <iostream>
int main()
{
LibraryInitializer init;
try {
X509_Certificate cert("somecert.pem");
X509_PublicKey* key = cert.subject_public_key();
std::cout << X509::PEM_encode(*key);
}
catch(std::exception& e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
---- CUT ----
-Jack
|