I have the following code for printing and generating a public and private key:
#include <openssl/err.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
int main()
{
BIO* outbio = NULL;
EC_KEY* myecc = NULL;
EVP_PKEY* pkey = NULL;
outbio = BIO_new_fp(stdout, BIO_NOCLOSE);
myecc = EC_KEY_new_by_curve_name(NID_secp256k1);
EC_KEY_generate_key(myecc);
pkey = EVP_PKEY_new();
EVP_PKEY_assign_EC_KEY(pkey, myecc);
myecc = EVP_PKEY_get1_EC_KEY(pkey);
const EC_GROUP* ecgrp = EC_KEY_get0_group(myecc);
BIO_printf(outbio, "ECC Key size: %d bit\n", EVP_PKEY_bits(pkey));
BIO_printf(outbio, "ECC Key type: %s\n", OBJ_nid2sn(EC_GROUP_get_curve_name(ecgrp)));
PEM_write_bio_PrivateKey(outbio, pkey, NULL, NULL, 0, 0, NULL);
PEM_write_bio_PUBKEY(outbio, pkey);
}
This produces output such as this:
ECC Key size: 256 bit
ECC Key type: secp256k1
-----BEGIN PRIVATE KEY-----
MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgFAwnckdtDYrNJUbl+sxv
wkUEZCaZTy69C/Mo957vlRihRANCAARgj+NiB2pCJkwb3yPmbD6Rxf/DIgOnbUwr
6sQrmwgq7kBqKVYp7Ar6GdqmnvXB/fSWBWCBzgT6oJO6v5Ixc0T2
-----END PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEYI/jYgdqQiZMG98j5mw+kcX/wyIDp21M
K+rEK5sIKu5AailWKewK+hnapp71wf30lgVggc4E+qCTur+SMXNE9g==
-----END PUBLIC KEY-----
This looks correct, however if I try to apply these keys to https://8gwifi.org/ecsignverify.jsp the keys do not function properly. If I put the keys in the public/private key input boxes, I get "null EC Private Key is not valid for Signature generation". I do not understand at all what the problem is.
Secondly, I intend to store these keys in some type of string format so that I can load them into memory easily. But how would I go about doing both a signing and verification using these two keys in string format in OpenSSL? I do not understand the ECDSA_sign function parameters nor the ECDSA_verify function parameters.