4

I'm using the below two lines to generate a hex of an ECDSA private key:

openssl ecparam -genkey -name secp256k1 -out data.pem

openssl ec -in data.pem -outform DER|tail -c +8|head -c 32|xxd -p -c 32

Those output something like this:

059f2c8f5b1978bcc02d4b41e75c3aae99f3194fb06b53ffd256178e1367a2a6

How can I then use that hex key to generate a public ECDSA key, something like this?

043d6fa62769c10ceb28d3c13ae1e2329888e99d9c8bf854cc5bdcea0b7cd3002a0f5d244e35eec297c8eb4098b75295328cdeebe7e39a5ac7539f0fc146fa3c99

Any help is appreciated.

Microondas
  • 71
  • 1
  • 5

2 Answers2

3

Try this one

openssl ec -in data.pem -pubout -out pubkey.pem
Chiara Hsieh
  • 3,273
  • 23
  • 32
-1

You can take the last 65 bytes of your private key you got from

openssl ecparam -genkey -name secp256k1 -out data.pem
openssl ec -in data.pem -outform DER

That's your public key too.

  • And your private key as well. Imagine sending that to somebody. OK, you described taking 65 bytes, which is only valid for the specific curve size (never mentioned) and your code doesn't actually implement it either. The result is *just* the public key point, which would not be accepted by a majority of implementations, and is missing the parameters. – Maarten Bodewes Feb 23 '19 at 14:00