[Botan-devel] Question with loading multiple public keys from a file

Jack Lloyd lloyd at randombit.net
Mon Apr 23 10:04:15 EDT 2007


On Mon, Apr 23, 2007 at 10:58:00PM +0900, Eunsoo Roh wrote:

> I'm writing an application to encrypt some data with RSA
> algorithm. I have a PEM file, which contains bunch of sets of public
> keys for encryption. It was a piece of cake to load single key with
> Botan's well-formed interface, but I have no idea at all to load
> multiple keys from a single file. How can I acquire key object for
> each sets and iterate/or specifically load nth key from it?

From a file, this is pretty easy, you want something like (untested,
may need tweaks):

DataSource_Stream in("rsakeys.pem");
std::vector<X509_PublicKey*> keys;
while(!in.end_of_data())
   {
   X509_PublicKey* key = 0;

   try {
      key = X509::load_key(in);
   }
   catch(Decoding_Error) { /* ignore (or maybe print what() */ }

   if(key)
      keys.push_back(key);
   }

(and if you want specifically RSA keys you can dynamic_cast them)

> BTW, even though application runs fine, it constantly prints warnings. Is this normal?

Probably not - can you post an example?

-J


More information about the botan-devel mailing list