[Botan-devel] How to import Openssl DER formated RSA key in Botan

Jack Lloyd lloyd at randombit.net
Tue Jan 19 08:38:16 EST 2010

On Tue, Jan 19, 2010 at 06:50:28PM +0530, Sudhanshu Shukla wrote:
> Hi folks,
> I have been struggling at importing OPENSSL DER formatted RSA keys in Botan.
> I have previously used libtomcrypt, which provides rsa_import function
> through which the openssl DER formated keys can be imported in libtomcrypt.
> I want some thing similar to that.

This is pretty easy but not directly supported since what OpenSSL is
doing is not a standard format. Something like the following program
will load such keys fine however:

#include <botan/botan.h>
#include <botan/rsa.h>

#include <iostream>

using namespace Botan;

int main()
   LibraryInitializer init;
   AutoSeeded_RNG rng;

   DataSource_Stream in("rsa.der");

   BigInt version, n, e, d, p, q, d1, d2, c;


   RSA_PrivateKey priv_key(rng, p, q, e, d, n);

   std::cout << std::hex << priv_key.get_p() << std::endl;
   std::cout << std::hex << priv_key.get_q() << std::endl;

More information about the botan-devel mailing list