Hello,

I'm would like to generate a key pair using the
openssl command line utilities and store them in
files.  The private key will be used by a Java program
that will do the signing.  The public key will be used
by a C++ program (using openssl lib) to do the
verification.

I am having trouble reconstituting the public key from
a DER format file.  I generated the file as follows:

> openssl genrsa prikey.dat 2048

> openssl rsa -in pri_key.dat -out pub_key.der \
  -outform DER -pubout

In my C++ program I read pub_key.der and attempt to
instantiate an RSA object:

    char filename[] = "pub_key.der";
    ifstream file1;
    
    
    file1.open(filename, std::ios::binary);
    char c;
    while (file1.get(c)) {
        bytes[i++] = (unsigned char) c;
    }
    file1.clear();
    file1.close();
    cout <<"Done reading public key - length is " << i
<< endl;
 
    const unsigned char *p = (const unsigned char *)
bytes;

    RSA *rsakey = NULL;
    rsakey = d2i_RSAPublicKey(NULL, &p, i);
    // alternatively:  d2i_RSAPublicKey(&rsakey, &p,
i);
        
    if (rsakey == NULL) {
        cout << "error reconstituting public key" << endl;
        return false;
    }

//...continue 


I get:
Done reading public key - length is 294
error reconstituting public key


Am I misunderstanding something about the
compatibility of "-outform DER" with
d2i_RSAPublicKey??

Thanks for any help,

Robin

PS 


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to