[Botan-devel] How to pass pubkey as string to X509::load_key

Jack Lloyd lloyd at randombit.net
Mon May 23 12:11:38 EDT 2005


It's a bit ugly, but this works:

DataSource_Memory keysrc((const byte*)keystring.c_str(), key.length());
X509_PublicKey* keyobj = X509::load_key(keysrc);

For a C-style string, it would be (haven't tried this one but it looks right):

DataSource_Memory keysrc((const byte*)keystring, std::strlen(keystring));

You could also do this with a MemoryVector with much the same result, something
like:

MemoryVector<byte> keysrc((const byte*)keystring.c_str(), key.length());

I would say using the DataSource_* objects makes more sense here, because you
could easily swap it out for a file loading one if that became useful, and also
I could imagine adding a std::string argument type to DataSource_Memory, while
that wouldn't ever really make sense for the low-level memory container types.

-Jack

On Tue, May 17, 2005 at 10:14:12AM +0800, sam wun wrote:
> Dear list,
> 
> Is there anyway I can pass a public key as a string to X509::load_key()?
> At the moment, the load_key does accept public key as a file name (the 
> file name is in string type). I didn't realised this problem. When I 
> passed in a public key as string to the load_key() function, the name of 
> the key was treated as a file name, therefore the key was loaded 
> successfully.
> If I need to pass a key in to the load_key(), I think I need to make it 
> as  a Memory Object first, then pass the Memory Object to the load_key() 
> function. How can covert the key into Memory Object before passing into 
> the load_key() function?
> 
> Thanks
> Sam
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://www.randombit.net/mailman/listinfo/botan-devel



More information about the botan-devel mailing list