<div dir="ltr">Hello all guys,<br><br>I'm a newbie... and going to understand the OpenSSL and the APIs involved in, and even if I searched in the Net, there are two main question/subject fields that I'd like to ask for.<br><br>1. Firstly, I wrote a little code that I don't know if it's really good enough. So, comments, suggestions... will be greatly appreciated.<br><br>----<br>#include <iostream><br>#include <openssl/ec.h><br>#include <openssl/pem.h><br>#include <openssl/err.h><br><br>#define ECCTYPE "brainpoolP512t1"<br><br>int generate_keys (EC_KEY * ecc, EVP_PKEY * pkey)<br>{<br>    if (EC_KEY_generate_key (ecc) <= 0)<br>        return 1;<br>    else<br>    {<br>        if (EVP_PKEY_assign_EC_KEY (pkey, ecc) <= 0)<br>            return 2;<br>        else<br>        {<br>            BIO * bp_public  = BIO_new_file ("./key.pub.pem", "w+");<br>            BIO * bp_private = BIO_new_file ("./key.prv.pem", "w+");<br><br>            if (bp_public)<br>            {<br>                if (PEM_write_bio_PUBKEY (bp_public, pkey) <= 0)<br>                    return 3;<br>                else<br>                    BIO_free_all (bp_public);<br>            }<br>            else<br>                return 4;<br><br>            if (bp_private)<br>            {<br>                if (PEM_write_bio_PrivateKey (bp_private, pkey, nullptr, nullptr, 0, 0, nullptr) <= 0)<br>                    return 5;<br>                else<br>                    BIO_free_all (bp_private);<br>            }<br>            else<br>                return 6;<br>        }<br>    }<br><br>    return 0;<br>}<br><br>int main()<br>{<br>    int retVal = 0;<br><br>    OpenSSL_add_all_algorithms();<br>    ERR_load_BIO_strings();<br>    ERR_load_crypto_strings();<br><br>    EVP_PKEY * pkey = EVP_PKEY_new();<br>    EC_KEY * ecc = EC_KEY_new_by_curve_name (OBJ_txt2nid (ECCTYPE));<br><br>    retVal = generate_keys (ecc, pkey);<br><br>    EVP_PKEY_free (pkey);<br>    EC_KEY_free (ecc);<br><br>    return retVal;<br>}<br>----<br><br>2. Secondly, I'd like to be able to work with these two generated keys... I mean, encrypt, decrypt... but don't reach to understand how to use them and which functions should be invoked ?<br><br>And also, I'd like to get the public/private keys... Should use EC_KEY_get0_private_key() & EC_KEY_get0_public_key() functions ?<br><br>Any help will be also highly appreciated.<br><br>Matt L.<br></div>