Title: Creating a public key from a private key using secp256k1 library in C++ Post by: chizisch on February 13, 2020, 06:54:44 PM Hello,
I'm trying to generate a public key from a private one using the bitcoin library secp256k1 https://github.com/bitcoin-core/secp256k1 (https://github.com/bitcoin-core/secp256k1) in C++: Code: // private key The output: Code: 1b9e55408c5141414e8337adef57ead18f62444fdf5f8c897d0dc812696a6141a919254d3e750075a2a9ba32dc4ed30c84e65f27e431b59b94a2aafe3e80a974 The idea is to parse the public key from the generated one to see if it is really correct. Also, i tried using openssl with the same private key and i get a different public key from the private one using ecdsa secp256k1.. Any help or example on how to use the library in C++ is more than welcome. Thank you ;D ;D Title: Re: Creating a public key from a private key using secp256k1 library in C++ Post by: A-Bolt on February 13, 2020, 10:01:52 PM Private key must be a 32-byte char array, not 64-byte hex string.
pkey.data is an internal representation of pubkey object. Don't use it. To get serialized pubkey use secp256k1_ec_pubkey_serialize (https://github.com/bitcoin-core/secp256k1/blob/856a01d6ad60c70fd92bdd44fa8584493b87594d/include/secp256k1.h#L348) function. Title: Re: Creating a public key from a private key using secp256k1 library in C++ Post by: chizisch on February 14, 2020, 12:12:47 AM Hello,
Thank you so much for your answer. Also, I have an additional newbie question as i am still not so good with data representations in C++ and how to deal with them. how do i convert a hex string to a 32bytes char array? I mean, if i convert that private key to ascii format it is gonna be 32-bytes, however it is just garbage non printable symbols most of time. Also, if you could guide me for some ressources i could use to well understand these conversions etc.. i will be more than grateful. Thank you again. Title: Re: Creating a public key from a private key using secp256k1 library in C++ Post by: pooya87 on February 14, 2020, 03:04:26 AM how do i convert a hex string to a 32bytes char array? the stackoverflow website is where you should go for these basic programming questions. here is two links that would answer your question: https://stackoverflow.com/questions/17261798/converting-a-hex-string-to-a-byte-array https://stackoverflow.com/questions/3221170/how-to-turn-a-hex-string-into-an-unsigned-char-array Also, if you could guide me for some ressources i could use to well understand these conversions etc.. i will be more than grateful. just use google to find out what each encoding is. for example for hexadecimal or base-16 encoding you can read the wikipedia article: https://en.wikipedia.org/wiki/HexadecimalTitle: Re: Creating a public key from a private key using secp256k1 library in C++ Post by: chizisch on February 14, 2020, 09:26:01 AM Thank you so much for your help ;D ;D ;D ;D
|