Hi, I have a problem with ECDSA private key that is preventing my progress. So please help if you can. Here is the setup:
I have an ECDSA private key in the form of a 32 byte unsigned char array, and a data that needs to be signed using that key. So I wrote the following code to load the key and use it to sign my data: unsigned char tempkey[100]; // buffer for the EC key int hdrlen = 31; int ftrlen = 32; memcpy(tempkey,"-----BEGIN EC PRIVATE KEY-----\n",hdrlen); // This is supposedly the required header memcpy(&tempkey[hdrlen],m_Private_key,32); //m_Private_key is a 32 byte unsigned char array memcpy(&tempkey[hdrlen+32],"==\n-----END EC PRIVATE KEY-----\n",ftrlen); // This is supposedly the // required footer tempkey[hdrlen+32+ftrlen] = 0; // NULL terminate just in case BIO* in; EC_KEY *pkey; in=BIO_new_mem_buf(tempkey,hdrlen+ftrlen+32); pkey=PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL); //Try to get an EC_KEY from tempkey And right there, pkey is returned to me as NULL. Does anyone know why this happen? Please advise me if you can. Because if it works fine, I can sign my data as follow: ECDSA_SIG *signature = ECDSA_do_sign(data_pointer,data_length, pkey); So please tell me what I did wrong. Thank you so much.