title: Signing a message using ECDSA in OpenSSL
body: <p>How do I set the private key for signing messages when using ECDSA in OpenSSL programmatically? I have the following code:</p>
  
  <pre><code>static int create_signature(unsigned char* hash)
  {
    EC_KEY *eckey=NULL;
    EC_GROUP *ecgroup=NULL;
    EVP_PKEY *evpkey=NULL;
    unsigned char *signature=NULL;
    point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;
    int signature_size, block_size;
    unsigned char * block=NULL;
  
    ecgroup = get_ec_group_192();
    EC_GROUP_set_asn1_flag(ecgroup, OPENSSL_EC_NAMED_CURVE);
    EC_GROUP_set_point_conversion_form(ecgroup, form);
    eckey=EC_KEY_new();
    EC_KEY_set_group(eckey,ecgroup);
    EC_KEY_generate_key(eckey);
    evpkey=EVP_PKEY_new();
    EVP_PKEY_assign_EC_KEY(evpkey,eckey);
    signature=OPENSSL_malloc(EVP_PKEY_size(evpkey));
  
    ECDSA_sign(0, hash, sizeof(hash), signature, &amp;signature_size, eckey);
  
    printf("%s", signature);
    return 0;
  }
  </code></pre>
  
  <p>The function <code>get_ec_group_192()</code> is created by running <code>openssl ecparam -C -name secp192k1 -genkey</code> which also generates some <code>EC PARAMETERS</code> and a <code>EC PRIVATE KEY</code>.</p>
  
  <p>What I am trying to do is to encrypt the message contained in <code>hash</code> with my private key so that only public key can decrypt it. Is that possible with the above code, or am I doing this completely wrong?</p>