Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4618264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:14:31+00:00 2026-05-22T02:14:31+00:00

How do I set the private key for signing messages when using ECDSA in

  • 0

How do I set the private key for signing messages when using ECDSA in OpenSSL programmatically? I have the following 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, &signature_size, eckey);

  printf("%s", signature);
  return 0;
}

The function get_ec_group_192() is created by running openssl ecparam -C -name secp192k1 -genkey which also generates some EC PARAMETERS and a EC PRIVATE KEY.

What I am trying to do is to encrypt the message contained in hash 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:14:32+00:00Added an answer on May 22, 2026 at 2:14 am

    The following verifies successfully for me:

    //compiled with gcc -g -lssl -UOPENSSL_NO_EC SO2228860.c -lcrypto
    #include <openssl/ec.h>      // for EC_GROUP_new_by_curve_name, EC_GROUP_free, EC_KEY_new, EC_KEY_set_group, EC_KEY_generate_key, EC_KEY_free
    #include <openssl/ecdsa.h>   // for ECDSA_do_sign, ECDSA_do_verify
    #include <openssl/obj_mac.h> // for NID_secp192k1
    
    
    static int create_signature(unsigned char* hash)
    {
        int function_status = -1;
        EC_KEY *eckey=EC_KEY_new();
        if (NULL == eckey)
        {
            printf("Failed to create new EC Key\n");
            function_status = -1;
        }
        else
        {
            EC_GROUP *ecgroup= EC_GROUP_new_by_curve_name(NID_secp192k1);
            if (NULL == ecgroup)
            {
                printf("Failed to create new EC Group\n");
                function_status = -1;
            }
            else
            {
                int set_group_status = EC_KEY_set_group(eckey,ecgroup);
                const int set_group_success = 1;
                if (set_group_success != set_group_status)
                {
                    printf("Failed to set group for EC Key\n");
                    function_status = -1;
                }
                else
                {
                    const int gen_success = 1;
                    int gen_status = EC_KEY_generate_key(eckey);
                    if (gen_success != gen_status)
                    {
                        printf("Failed to generate EC Key\n");
                        function_status = -1;
                    }
                    else
                    {
                        ECDSA_SIG *signature = ECDSA_do_sign(hash, strlen(hash), eckey);
                        if (NULL == signature)
                        {
                            printf("Failed to generate EC Signature\n");
                            function_status = -1;
                        }
                        else
                        {
    
                            int verify_status = ECDSA_do_verify(hash, strlen(hash), signature, eckey);
                            const int verify_success = 1;
                            if (verify_success != verify_status)
                            {
                                printf("Failed to verify EC Signature\n");
                                function_status = -1;
                            }
                            else
                            {
                                printf("Verifed EC Signature\n");
                                function_status = 1;
                            }
                        }
                    }
                }
                EC_GROUP_free(ecgroup);
            }
            EC_KEY_free(eckey);
        }
    
      return function_status;
    }
    
    int main( int argc , char * argv[] )
    {
        unsigned char hash[] = "c7fbca202a95a570285e3d700eb04ca2";
        int status = create_signature(hash);
        return(0) ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have the following code below to generate an OpenSSL RSA public and private
I have a public/private key pair set up so I can ssh to a
Take the following property: public string Foo { get; private set; } Using reflection,
I have generated a public key, private key pair. I've set the public key
like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field
Suppose I have a class public class MyClass { private Set<String> set = new
If I have a class that contains properties with private set and protected set
struct Drink { public string Name { get; private set; } public int Popularity
How do I calculate the private working set of memory using C#? I'm interested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.