<p>To generate an Elliptic Curve private key in PEM format using the <code>secp256k1</code> curve (which is the one used in Bitcoin):</p>

<pre><code>openssl ecparam -genkey -name secp256k1 -out tmp/data.pem
</code></pre>

<p>To convert the private key from PEM (human-readable and extended) to a hex format:</p>

<pre><code>openssl ec -in tmp/data.pem -outform DER|tail -c +8|head -c 32|xxd -p -c 32
</code></pre>

<p>To retrieve the public key in a hex format:</p>

<pre><code>openssl ec -in tmp/data.pem -pubout -outform DER|tail -c 65|xxd -p -c 65
</code></pre>

<p><strong>Explanation of the piped commands above</strong>  </p>

<p>1) <code>openssl ec -in tmp/data.pem -outform DER</code><br>
    Converts the private key from PEM to DER (binary) format.<br>
2) <code>tail -c +8</code><br>
    Skips the first (due to "+") 8 bytes (due to "c"), which should be the header of the DER format.<br>
3) <code>head -c 32</code><br>
    Returns the first 32 bytes which is the private key length.<br>
4) <code>xxd -p -c 32</code><br>
    Does a hex dump on the binary format of the key.   </p>

<ul>
<li><code>-p</code> is for having the output in plain hexdump style  </li>
<li><code>-c 32</code> is for having the 32 characters in one line, default is 16.  </li>
</ul>

CC BY-SA 3.0
2016-12-20T03:35:21.517Z
What are those `xxd`'s about?
DepressedDaniel
CC BY-SA 3.0
2017-09-14T17:46:33.223Z
What's the background of getting the pub/priv Bitcoin key from the ecda keypair?
soupdiver
CC BY-SA 4.0
2019-01-30T12:34:02.940Z
@DepressedDaniel I've edited the answer with more information about `xxd`.
Chris
CC BY-SA 4.0
2013-06-26T11:49:17.940Z
2019-01-30T11:34:22.583Z
2019-01-30T11:34:22.583Z
diyism
<p>Install OpenSSL. When the executable in your path, enter this command to generate a private key:</p>

<pre><code>openssl ecparam -genkey -name secp256k1 -noout -out myprivatekey.pem
</code></pre>

<p>To create the corresponding public key, do this:</p>

<pre><code>openssl ec -in myprivatekey.pem -pubout -out mypubkey.pem
</code></pre>

<p>This will give you both keys in PEM format. I'm not sure what format the web page wants, but it shouldn't be difficult to convert. You can use variants of the last command to output other formats. Remove <code>-pubout</code> if you want the private key, leave it if you want the public key. And you can use <code>-outform DER</code> to get DER format. You can use <code>-text</code> to get hexadecimal.</p>

<p>Do not give any form of your private key to anyone else.</p>

CC BY-SA 3.0
2012-10-28T06:44:08.300Z
2012-10-28T06:44:08.300Z
David Schwartz
<p>I want to know because I would like to generate a vanity address at <a href="https://vanitypool.appspot.com/" rel="noreferrer">Vanity Pool</a>.</p>

<vanity-address><ecdsa>
For a non-technical person, how do I generate a ECDSA key pair easily?
user1161604
# For a non-technical person, how do I generate a ECDSA key pair easily?

(Asked by: username_0 on 2012-10-28)

I want to know because I would like to generate a vanity address at [Vanity Pool](https://vanitypool.appspot.com/).

**Tags:** vanity-address, ecdsa


---

## 2 answers

### Answer by username_5 on 2012-10-28. Score: 15 | Accepted answer

Install OpenSSL. When the executable in your path, enter this command to generate a private key:

```
openssl ecparam -genkey -name secp256k1 -noout -out myprivatekey.pem

```

To create the corresponding public key, do this:

```
openssl ec -in myprivatekey.pem -pubout -out mypubkey.pem

```

This will give you both keys in PEM format. I'm not sure what format the web page wants, but it shouldn't be difficult to convert. You can use variants of the last command to output other formats. Remove `-pubout` if you want the private key, leave it if you want the public key. And you can use `-outform DER` to get DER format. You can use `-text` to get hexadecimal.

Do not give any form of your private key to anyone else.


---

### Answer by username_1 on 2013-06-26. Score: 4

To generate an Elliptic Curve private key in PEM format using the `secp256k1` curve (which is the one used in Bitcoin):

```
openssl ecparam -genkey -name secp256k1 -out tmp/data.pem

```

To convert the private key from PEM (human-readable and extended) to a hex format:

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

```

To retrieve the public key in a hex format:

```
openssl ec -in tmp/data.pem -pubout -outform DER|tail -c 65|xxd -p -c 65

```

**Explanation of the piped commands above**

1) `openssl ec -in tmp/data.pem -outform DER`  
Converts the private key from PEM to DER (binary) format.  
2) `tail -c +8`  
Skips the first (due to "+") 8 bytes (due to "c"), which should be the header of the DER format.  
3) `head -c 32`  
Returns the first 32 bytes which is the private key length.  
4) `xxd -p -c 32`  
Does a hex dump on the binary format of the key.

* `-p` is for having the output in plain hexdump style
* `-c 32` is for having the 32 characters in one line, default is 16.

> **Comments:**
> **username_2**: What are those `xxd`'s about?  
> **username_3**: What's the background of getting the pub/priv Bitcoin key from the ecda keypair?  
> **username_4**: @username_2 I've edited the answer with more information about `xxd`.  

---

