[Botan-devel] Getting the binary form of the key

Z. S. O. tiredashell at gmail.com
Wed Oct 7 23:03:03 EDT 2009

I've had an easy enough job getting the PKCS8-encoded version of
an RSA_PrivateKey and its X509-encoded equivalent, as seen below, but I'd
prefer just getting the raw binary version of the keys encoded as a byte
array. Is there a simple function with this purpose that I am missing? I'm
thinking something along the lines of the bits_of function for a
Botan::AutoSeeded_RNG rng;

//Generate private key
Botan::u32bit bits = 2048;
Botan::RSA_PrivateKey key(rng, bits);
std::string privKey = Botan::PKCS8::PEM_encode(key);

//Derive public key
Botan::DataSource_Memory key_src(privKey);
Botan::Private_Key* pkcs8 = Botan::PKCS8::load_key(key_src, rng);
std::string pubKey = Botan::X509::PEM_encode(*pkcs8);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20091007/530b0552/attachment.html>

More information about the botan-devel mailing list