Load ECIES public key

Viewed 275

[Generated public key following (https://jameshfisher.com/2017/04/14/openssl-ecc/)

Alice generates her private key:

openssl ecparam -name secp256k1 -genkey -noout -out alice_priv_key.pem

Alice extracts her public key from her private key:

openssl ec -in alice_priv_key.pem -pubout -out alice_pub_key.pem

I have a application in C when I need to send encrypted data using public key. I am trying to load the data from public (alice_pub_key.pem) file.

I converted PEM file to hex data from (https://holtstrom.com/michael/tools/hextopem.php).

So seems I am not providing data in proper format. Can anyone suggest whats going wrong?

key = EC_KEY_new_by_curve_name(NID_secp256k1)
group = EC_KEY_get0_group(key)
pub_key = EC_POINT_new(group)
EC_POINT * point = EC_POINT_hex2point(group, ptr, pub_key, NULL)

This point its returning null.

1 Answers

You can try PEM_read_EC_PUBKEY to read the public key. This avoids having to parse or re-encode the public key itself.

Note that you may need a recent OpenSSL for this; it is hard to find out from the documentation when this function was introduced.

Related