[Botan-devel] Unable to read a rsa private key generated by openssl

Pete Toich torcher72 at yahoo.com
Fri Jun 11 17:53:10 EDT 2010


Hi,

When I try to use the following code to read a pem file generated by openssl (syntax below),
 I get the exception: Exception: Botan: Decoding error: PKCS #8 private key decoding failed

Looking at the pem file generated by openssl and by the rsa_kgen botan example, the file sizes are different.  Diving deeper there is
a extra header on the rsa_kgen version that is not present in the openssl version.  

Is it possible to open RSA keys with botan that were created by openssl?

Thanks for any help,
Pete


openssl rsa private key generated by:
 openssl genrsa -out mykey.pem 2048

openssl rsa public key generated by:
openssl rsa -in mykey.pem -pubout > mykey_pub.pem

============ code snippet ============================================

 try 
    {
        std::auto_ptr<PKCS8_PrivateKey> key(PKCS8::load_key("mykey.pem", rng ));

        printf("%s, %i: Loaded rsa private 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__ );

        decrypted_data = rsakey->decrypt( 
                encrypted_data,
                sizeof(test_data) );
        
        printf("%s, %i: Decrypted data:\n", __FILE__, __LINE__ );
        display_hex_data( decrypted_data, sizeof(test_data) );

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




More information about the botan-devel mailing list