6
1
Given a private key, I can get the uncompressed or compressed version of the public key like so.
EC_KEY* pKey = EC_KEY_new_by_curve_name(NID_secp256k1);
std::vector<unsigned char> getPubKey(EC_KEY* pKey, bool compressed) const {
if (compressed)
EC_KEY_set_conv_form(pKey, POINT_CONVERSION_COMPRESSED);
else
EC_KEY_set_conv_form(pKey, POINT_CONVERSION_UNCOMPRESSED);
int nSize = i2o_ECPublicKey(pKey, NULL);
std::vector<unsigned char> pubKey(nSize, 0)
unsigned char* pBegin = &pubKey[0];
i2o_ECPublicKey(pKey, &pBegin)
return pubKey;
}
But how can I get the uncompressed public key from the compressed public key without knowing the private key?
1
I answered the same question here, but with an answer in Python: https://bitcointalk.org/index.php?topic=644919.msg7205689#msg7205689 If a language-agnostic answer is suitable, I can post this as an answer.
– Tim S. – 2014-07-09T17:59:34.223Thanks for the solution, but I'm looking fora a canonical solution using openssl. – user299648 – 2014-07-09T19:39:32.610