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

Z. S. O. tiredashell at gmail.com
Fri Oct 9 22:08:15 EDT 2009

By the way, I'm guessing that the load_key function is still unable to
decode a RAW_BER encoded key, correct? I tried it unsuccessfully, so I chose
to PEM-encode it before giving it to load_key, which works fine even though
it's sort of roundabout. Here's my code:


On Thu, Oct 8, 2009 at 11:20 PM, Z. S. O. <tiredashell at gmail.com> wrote:

> Yeah I apologize for my imprecise terminology, I meant that I needed a
> function to give me a private or public key without the PEM encoding, which
> I incorrectly referred to as the PKCS8 and X509 encoding. It looks like the
> "encode" function will do the trick -- it should have been obvious to me as
> I searched the docs, but my eyes were looking for a function that returned
> an std::string so I missed it. Thanks again.
> On Wed, Oct 7, 2009 at 11:10 PM, Jack Lloyd <lloyd at randombit.net> wrote:
>> On Wed, Oct 07, 2009 at 11:03:03PM -0400, Z. S. O. wrote:
>> > 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
>> > SymmetricKey.
>> The functions PKCS8::encode() and PKCS8::encrypt_key() will produce
>> the raw binary PKCS #8 serialization, sending the data into a Pipe&.
>> X509::encode() will do the same for a public key.
>> I'm not sure if this exactly what you mean by 'raw binary' - the
>> output will be the same as the PEM encode variants (except, obviously,
>> with the PEM encoding). The PKCS #8 and subjectPublicKeyInfo formats
>> have the advantage of being portable across systems and
>> implementations, though.
>> You could also roll something on your own using BigInt::encode(), but
>> of course you'd have to deal with all the length fields, etc yourself
>> and nothing else will be able to understand it without special help.
>> -Jack
>> _______________________________________________
>> botan-devel mailing list
>> botan-devel at randombit.net
>> http://lists.randombit.net/mailman/listinfo/botan-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20091009/1651eee0/attachment.html>

More information about the botan-devel mailing list