[Botan-devel] Trying to pass a RSA key from memory to RSA Private

Pete Toich torcher72 at yahoo.com
Thu Jun 10 18:22:18 EDT 2010


Hi,

I am working on a project that requires storing a RSA key in secure memory provided by the hardware.  Once allocated it behaves like regular memory for a code execution standpoint.  I am trying to load the botan RSA object with that data without storing it to disk.  I know that I can easily use the PKCS8::load_key method to bring the key in from a file, but I have an requirement to keep the key in secure memory.  I tried the code snippet below, which tries to use a DataSource_Memory object but this exceptions with " Exception: basic_string::_S_construct NULL not valid".  Am I missing it or is there no way to load a key from memory?

Thanks for any help,
Pete


================ code snippet ===============================================
    try 
    {
        DataSource_Memory key_data( priv_exchange_key_p, priv_exchange_key_len );

        std::auto_ptr<PKCS8_PrivateKey> key(PKCS8::load_key(key_data, rng, NULL));
        printf("%s, %i: Loaded rsa key file\n", __FILE__, __LINE__ );

        RSA_PrivateKey* rsakey = dynamic_cast<RSA_PrivateKey*>(key.get());
        if(!rsakey)
        {
            std::cout << "The loaded key is not a RSA key!\n";
            exit(1);
        }
        printf("%s, %i: Key file is valid\n", __FILE__, __LINE__ );

        SecureVector<byte> decrypted_data = rsakey->decrypt( 
                contentSetKeyE_Rsa2048_p,
                content_set_key_length );
        
        printf("%s, %i: Decrypted data:\n", __FILE__, __LINE__ );
        for ( unsigned int i = 0; i < content_set_key_length; i ++ ) {
            printf("0x%2x ", decrypted_data[i] );
        }
        printf("\n");

      //for ( int i = 0; i < ENCRYPTED_CONTENT_SET_KEY_SIZE_C; i ++ ) {
      //    PlayerKeyring[device].ContentSetKeyE_Rsa2048[i] = encrypted_data[i];
      //}

    }
    catch(std::exception& e)
    {
        std::cout << "Exception: " << e.what() << std::endl;
        exit(1);
    }
==================== end snippet =============================================



More information about the botan-devel mailing list