<p>OpenSSL will compute a public key corresponding to a private key, try:</p>
<pre><code>$ openssl ec -in private_key.openssl.pem -text 
</code></pre>
<p>There must be correct input provided to OpenSSL. It is not enough to convert private key from hex string to base64 in order for it to be accepted by OpenSSL. There must be eliptic curve parameters included in the .pem file, like shown in the short script:</p>
<blockquote>
<p><a href="https://gist.github.com/vkobel/52048e12d8930ef63930949a717ddcbf" rel="nofollow noreferrer">https://gist.github.com/vkobel/52048e12d8930ef63930949a717ddcbf</a></p>
</blockquote>

CC BY-SA 4.0
2023-02-15T08:35:26.857Z
2023-02-15T08:35:26.857Z
Greg Tonoski
<p>I want to generate bitcoin priv/pub key manually.
I generated random binary numbers by flipping some coins and converted them to hex.</p>
<p>Now,I got a bitcoin private key
in hex:<code>d1267088f0defab13969dd34c899d28268119cf9e68f3856d0ee9b581f5a1bca</code></p>
<p>in WIF:<code>L4EGhR5Fdon96W2zepTAE3CxtayBqiN3v2pBmkB9dxG4r8JaVKf2</code></p>
<p>how to gerate Public Key using openssl command line in linux?</p>
<p>I tried to use</p>
<pre><code>openssl ec -in priv_key.pem -pubout
</code></pre>
<p>but terminal said: unable to load Key, and lots error file uris.</p>
<p>Maby I got something wrong with PEM private key format.</p>
<p>The priv_key.pem ,I converted private key hex to base64 format.</p>
<pre><code>-----BEGIN EC PRIVATE KEY-----
ZDEyNjcwODhmMGRlZmFiMTM5NjlkZDM0Yzg5OWQyODI2ODExOWNmOWU2OGYzODU2
ZDBlZTliNTgxZjVhMWJjYQ==
-----END EC PRIVATE KEY-----
</code></pre>

CC BY-SA 4.0
2023-02-15T02:26:08.557Z
The SECG format for EC privatekey used by OpenSSL is quite different from just the raw bits/number 'd' used in Bitcoin. See crossdupe https://stackoverflow.com/questions/48101258/how-to-convert-an-ecdsa-key-to-pem-format -- where my answer is based on https://bitcoin.stackexchange.com/questions/66594/ but that requires both privatekey and publickey and you apparently don't have publickey (yet; my answer derives it).
dave_thompson_085
<private-key><public-key><openssl>
How to generate a bitcoin public key from an existing private key using openssl?
MonKong
# How to generate a bitcoin public key from an existing private key using openssl?

(Asked by: username_0 on 2023-02-14)

I want to generate bitcoin priv/pub key manually.
I generated random binary numbers by flipping some coins and converted them to hex.
Now,I got a bitcoin private key
in hex:d1267088f0defab13969dd34c899d28268119cf9e68f3856d0ee9b581f5a1bca
in WIF:L4EGhR5Fdon96W2zepTAE3CxtayBqiN3v2pBmkB9dxG4r8JaVKf2
how to gerate Public Key using openssl command line in linux?
I tried to use
openssl ec -in priv_key.pem -pubout

but terminal said: unable to load Key, and lots error file uris.
Maby I got something wrong with PEM private key format.
The priv_key.pem ,I converted private key hex to base64 format.
-----BEGIN EC PRIVATE KEY-----
ZDEyNjcwODhmMGRlZmFiMTM5NjlkZDM0Yzg5OWQyODI2ODExOWNmOWU2OGYzODU2
ZDBlZTliNTgxZjVhMWJjYQ==
-----END EC PRIVATE KEY-----

**Tags:** private-key, public-key, openssl

> **Comments:**
> **username_1**: The SECG format for EC privatekey used by OpenSSL is quite different from just the raw bits/number 'd' used in Bitcoin. See crossdupe https://stackoverflow.com/questions/48101258/how-to-convert-an-ecdsa-key-to-pem-format -- where my answer is based on https://bitcoin.stackexchange.com/questions/66594/ but that requires both privatekey and publickey and you apparently don't have publickey (yet; my answer derives it).  

---

## 1 answers

### Answer by username_2 on 2023-02-15. Score: 1

OpenSSL will compute a public key corresponding to a private key, try:
$ openssl ec -in private_key.openssl.pem -text 

There must be correct input provided to OpenSSL. It is not enough to convert private key from hex string to base64 in order for it to be accepted by OpenSSL. There must be eliptic curve parameters included in the .pem file, like shown in the short script:

https://gist.github.com/vkobel/52048e12d8930ef63930949a717ddcbf


---

