[Autocrypt] How to create the "raw key" part from an RSA key

Bjoern b44treader at googlemail.com
Tue May 16 07:13:01 EDT 2017


Hi there,

I'm just about to add AutoCrypt to Delta Chat.

I'm creating the key pair using the following code:

    // generate key
    BIGNUM*       e   = BN_new();
    RSA*          rsa = RSA_new();

    BN_set_word(e, 65537);
    if( RSA_generate_key_ex(rsa, 2024, e, 0) != 1 ) {
        goto cleanup;
    }

    //  convert RSA key to PUBLIC KEY
    EVP_PKEY* pkey = EVP_PKEY_new();
    EVP_PKEY_set1_RSA(pkey, rsa);

now I can get the keys as `-----BEGIN PUBLIC KEY----- ...` and
`-----BEGIN RSA PRIVATE KEY----- ...` using

PEM_write_bio_PUBKEY(bio1, pkey);

and

PEM_write_bio_RSAPrivateKey(bio2, rsa, NULL, NULL, 0, NULL, NULL);

But how can I get the key in the "raw" form needed by Autocrypt?
(base64 encoding itself is no problem)

(for various reasons, I cannont use libraries based upon GnuPG as PEP
or GPGME and I wanted a portable C code)

Any help is wecome as this would saves me tons of time :-) (I am not
expert in OpenSSL)



More information about the Autocrypt mailing list