ed-public-key-to-send-to-a-peer">Get an encoded public key to send to a peer</h2>

<pre><code>#include &lt;openssl/evp.h&gt;

int get_encoded_pub_key(EVP_PKEY *ourkey)
{
    unsigned char *pubkey;
    size_t pubkey_len;

   pubkey_len = EVP_PKEY_get1_encoded_public_key(ourkey, &amp;pubkey);
   if (pubkey_len == 0)
       return 0;

   /*
    * Send the encoded public key stored in the buffer at &quot;pubkey&quot; and of
    * length pubkey_len, to the peer.
    */

   OPENSSL_free(pubkey);
   return 1;
}</c