Hey! I've been trying to read key pairs from cryptopp. I've managed to read
the public keys with this code:

RSA* readPublicKey(const string& key)
{
        int base64_len = key.length() + 2;
        char base64[base64_len];
                memcpy(&base64[0], key.c_str(), key.length());
        base64[key.length()] = '\n';
        base64[key.length()+1] = 0;
        
        BIO* mem = BIO_new_mem_buf(&base64[0], -1);
        BIO* b64 = BIO_new(BIO_f_base64());
        mem = BIO_push(b64, mem);
        
        // Base64 is 4/3 times too big.
        int raw_len = key.length() * 3/4 + 1;
        unsigned char raw[raw_len];
        int len = BIO_read(mem, reinterpret_cast<char*>(&raw[0]), raw_len);
        raw[len] = 0;
        
        BIO_free_all(mem);

        unsigned char* p = &raw[0];
        return d2i_RSAPublicKey(NULL, &p, raw_len);
}

However, now I need to read their private key. Because it is protected with
a passphrase, I am not sure how to proceed. I am not sure if pem is the
format I should be trying to read or not.

Ideally I want to make a function:
RSA* readPrivateKey(const string& key, const string& passphrase);

Which returns NULL if the passphrase or key format is wrong.

Could someone suggest what to do?

Thanks.

-- 
Wesley W. Terpstra <[EMAIL PROTECTED]>
Javien Canada Inc. - Linux Developer

PGP signature

Reply via email to