[Botan-devel] PKCS8

Jack Lloyd lloyd at randombit.net
Thu Dec 18 01:39:05 EST 2008


On Mon, Dec 15, 2008 at 11:31:06AM -0800, Alex Castillo wrote:
> Hello,
>
> I'm trying to open a PKCS8 DER encoded RSA key using:
> PKCS8_PrivateKey* load_key(DataSource& in, RandomNumberGenerator& rng, std::string passphrase = "");
>
> but I cannot achieve it, I get an unexpected crash in the application.

Hi Alex,

Hrm, this works for me:

(motoko ~)$ cat rsa.cpp

#include <botan/botan.h>
#include <botan/pkcs8.h>
#include <iostream>

using namespace Botan;

int main()
   {
   LibraryInitializer init;

   DataSource_Stream in("aaa010101aaa_CSD_01.key");
   std::string pass = "a0123456789";

   AutoSeeded_RNG rng;

   PKCS8_PrivateKey* key = PKCS8::load_key(in, rng, pass);

   std::cout << PKCS8::PEM_encode(*key);
   }

(motoko ~)$ !g+
g++ rsa.cpp -lbotan -o rsa
(motoko ~)$ ./rsa
-----BEGIN PRIVATE KEY-----
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOmaJbWr2DLMIW0x
xtoUMl7GTYikuhN01eDhOgZFn9/6EiOaPc3o4NZfUBE0UZihwQd/XXcalbk57+aP
pSqEGmIfglFM1HhR1vybIlMCsiU4PKdUe4hS7KEqjuBsxsN1eOKVMBhjZdZC5Dto
O1bCe1SY2Di8AL8Xc61HPf7L3AzlAgMBAAECgYB82Qeiaq9nprWOuHXAg97PzEgP
6YoRb/YG9Big1YE2oV4kbQDvFbFkoRgXudCKNJkHushnKWwvzIksvkTVzjiShz7b
5Lo4XqBxa6NwtHlQVEhmxzGjR7WujfTBJPIwFx0F5YBJtoTLv7swXjpbSECEETtv
j0lSZ27PV8GO0016gQJBAPdVs0Cxt//3RXBlV7FRdY2q7A+wBmOZ2kvVN7VF0Lm3
GPYRtR0M9ppgLVwJdeNuV/2uzLJWJSjCw21yeH3bBJECQQDxyUgc5sRKJlkSd22Z
i5GWAuxfYav+qjfS4BS6sfunxDTtJY5kImQ48lSGHapqdhmyew5gdb70GvlTqAOS
fF0VAkEAui5r2dYt0OOdBMd0pIjSOYshWYnCtXUaCx18atscDMCUbJ7VvAGHHJwr
aO3CLSph2BeeBNyt6in6HEggBXU50QJBALu/utmGcGHLyVrHljmm4RQFjRq7s1z7
PIHpMu+OCYZKm3aStTEYa460zeGe45frwSSQ3acVh4Px9i15x9xV6ckCQQDEz5DO
hV0mnDX+KOH4h9nl42G8wrZuPgN77/ZLHkpln1KIjttFo6MF+9ojsCR4fQumKFRF
bXZm3uFm/yQLTnwm
-----END PRIVATE KEY-----

Also: are you catching exceptions? With some compilers/runtimes,
an uncaught exception looks quite like a crash.

-Jack



More information about the botan-devel mailing list