<p>Openssl can be used to convert private keys to public keys. The following command gives you the public key from a known private key. The private key should be in the form of a PEM file:</p>

<pre>
$ cat private_key.pem

-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMURrYd6CTHlrrV0JOxnze9ldaq3mRYMnYJ8195GldAVoAcGBSuBBAAK
oUQDQgAEANPTV3v+8AMXnIPaerOWziyc6tHbmbhORhbVKv1ACYuO+ohlFaV6QaOz
/AGjoSXV0ZeKxq7FijsAdBzeu23Fgg==
-----END EC PRIVATE KEY-----
</pre>

<p><strong>Note:</strong> if you have a private key in hex format, then you should convert it to PEM format, using the procedure of this <a href="https://bitcoin.stackexchange.com/questions/66594/signing-transaction-with-ssl-private-key-to-pem">answer</a>.</p>

<p>To obtain the public key from the private key we use openssl:</p>

<pre>
$ openssl ec -pubout /dev/null

-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEANPTV3v+8AMXnIPaerOWziyc6tHbmbhO
RhbVKv1ACYuO+ohlFaV6QaOz/AGjoSXV0ZeKxq7FijsAdBzeu23Fgg==
-----END PUBLIC KEY-----
</pre>

<p>In order to convert a public key to a bitcoin address, we need some <a href="https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#How_to_create_Bitcoin_Address" rel="nofollow noreferrer">steps</a>:</p>

<p>First we need to <strong>compute the hash160</strong> of the public key. This can be done as follows:</p>

<pre>
$ openssl ec -pubout /dev/null |
  openssl ec -pubin -pubout -outform DER 2>/dev/null |
  tail -c 65 |
  openssl dgst -sha256 -binary |
  openssl dgst -rmd160 -binary |
  xxd -p -c 80

ab085c55b735d4a811df3f55e6508634f1ce1e27
</pre>

<p>Then the hash160 has to be used to <strong>calculate the checksum</strong> as follows:</p>

<pre>
$ echo -n "ab085c55b735d4a811df3f55e6508634f1ce1e27" |
  xxd -p -r |
  openssl dgst -sha256 -binary |
  openssl dgst -sha256 -binary |
  xxd -p -c 80 |
  head -c 8

7801f8dc
</pre>

<p>The hash160, combined with the checksum and with the first byte "00", can be <strong>encoded using base 58</strong>. This gives us the address:</p>

<pre>
base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

encodeBase58() {
    # 58 = 0x3A
    bc 0) { n%3A ; n/=3A }" |
    tac |
    while read n
    do echo -n ${base58[n]}
    done
}
</pre>

<pre>
$ printf "%34s\n" "$(encodeBase58 "00$1$(checksum "$char$1")")" |
  sed "y/ /1/"

1GbLZiNzi7DTB4UowMuyqJw5Bh95yCbu3R
</pre>

<p><strong>Putting all together</strong>, we can use the function publicKeyToAddress, as defined below. This can be part of a bash script, or you can type it on the command line.</p>

<pre>
base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

encodeBase58() {
    # 58 = 0x3A
    bc 0) { n%3A ; n/=3A }" |
    tac |
    while read n
    do echo -n ${base58[n]}
    done
}

checksum() {
    xxd -p -r /dev/null |
    tail -c 65 |
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -binary |
    xxd -p -c 80
    )
}
</pre>

<pre>
$ openssl ec -pubout /dev/null | publicKeyToAddress

1GbLZiNzi7DTB4UowMuyqJw5Bh95yCbu3R
</pre>

CC BY-SA 4.0
2019-02-09T18:18:05.883Z
2019-02-28T13:18:35.247Z
2019-02-28T13:18:35.247Z
Luca Venturini
<p>If you don't want to do it online, you can try to import the private key into Bitcoin-Qt then see if the matching public key is the one you expected. </p>

CC BY-SA 3.0
2013-01-02T17:27:39.257Z
2013-01-02T17:27:39.257Z
lurf jurv
<p>My best recommendation is to try and import the private key into <a href="https://blockchain.info/wallet/" rel="nofollow">https://blockchain.info/wallet/</a> service. This can be found under the advanced tab of the wallet. The corresponding public key will be added into your wallet for deposits. </p>

<p>A second option which does not require and account is to go via <a href="https://www.bitaddress.org" rel="nofollow">https://www.bitaddress.org</a> and parse it with the vanity address tab.</p>

CC BY-SA 3.0
2012-12-10T16:01:02.430Z
2012-12-10T16:01:02.430Z
MaxSan
<p>The <a href="https://github.com/richardkiss/pycoin" rel="nofollow">pycoin</a> Python library could be a good starting point. It has a utility that will give you the public key for a given private key. Unfortunately it doesn't seem to have a command line interface suitable for easy programmatic use.</p>

CC BY-SA 3.0
2013-12-01T13:39:16.993Z
2013-12-01T13:39:16.993Z
Acorn
<p>I ran vanitygen and oclvanitygen on the same machine, and realized after my run that both exe's share the same output file.</p>

<p>I've had experience in the past where many programs append to the same TXT file that corruption might happen.</p>

<p>Regardless of the source of the corruption, what is the most complete way to validate a key created by vanitygen?</p>

<p><strong>Update</strong></p>

<p>I added the developer tag since I'm looking to do validation in bulk.  Command line scripts also work.</p>

<development><encryption><vanitygen>
How can I test and verify a vanity key before I send coins to it?
makerofthings7
# How can I test and verify a vanity key before I send coins to it?

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

I ran vanitygen and oclvanitygen on the same machine, and realized after my run that both exe's share the same output file.

I've had experience in the past where many programs append to the same TXT file that corruption might happen.

Regardless of the source of the corruption, what is the most complete way to validate a key created by vanitygen?

**Update**

I added the developer tag since I'm looking to do validation in bulk. Command line scripts also work.

**Tags:** development, encryption, vanitygen


---

## 4 answers

### Answer by username_1 on 2019-02-09. Score: 1

Openssl can be used to convert private keys to public keys. The following command gives you the public key from a known private key. The private key should be in the form of a PEM file:

```

$ cat private_key.pem

-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMURrYd6CTHlrrV0JOxnze9ldaq3mRYMnYJ8195GldAVoAcGBSuBBAAK
oUQDQgAEANPTV3v+8AMXnIPaerOWziyc6tHbmbhORhbVKv1ACYuO+ohlFaV6QaOz
/AGjoSXV0ZeKxq7FijsAdBzeu23Fgg==
-----END EC PRIVATE KEY-----

```

**Note:** if you have a private key in hex format, then you should convert it to PEM format, using the procedure of this [answer](https://bitcoin.stackexchange.com/questions/66594/signing-transaction-with-ssl-private-key-to-pem).

To obtain the public key from the private key we use openssl:

```

$ openssl ec -pubout /dev/null

-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEANPTV3v+8AMXnIPaerOWziyc6tHbmbhO
RhbVKv1ACYuO+ohlFaV6QaOz/AGjoSXV0ZeKxq7FijsAdBzeu23Fgg==
-----END PUBLIC KEY-----

```

In order to convert a public key to a bitcoin address, we need some [steps](https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#How_to_create_Bitcoin_Address):

First we need to **compute the hash160** of the public key. This can be done as follows:

```

$ openssl ec -pubout /dev/null |
  openssl ec -pubin -pubout -outform DER 2>/dev/null |
  tail -c 65 |
  openssl dgst -sha256 -binary |
  openssl dgst -rmd160 -binary |
  xxd -p -c 80

ab085c55b735d4a811df3f55e6508634f1ce1e27

```

Then the hash160 has to be used to **calculate the checksum** as follows:

```

$ echo -n "ab085c55b735d4a811df3f55e6508634f1ce1e27" |
  xxd -p -r |
  openssl dgst -sha256 -binary |
  openssl dgst -sha256 -binary |
  xxd -p -c 80 |
  head -c 8

7801f8dc

```

The hash160, combined with the checksum and with the first byte "00", can be **encoded using base 58**. This gives us the address:

```

base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

encodeBase58() {
    # 58 = 0x3A
    bc 0) { n%3A ; n/=3A }" |
    tac |
    while read n
    do echo -n ${base58[n]}
    done
}

```

```

$ printf "%34s\n" "$(encodeBase58 "00$1$(checksum "$char$1")")" |
  sed "y/ /1/"

1GbLZiNzi7DTB4UowMuyqJw5Bh95yCbu3R

```

**Putting all together**, we can use the function publicKeyToAddress, as defined below. This can be part of a bash script, or you can type it on the command line.

```

base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

encodeBase58() {
    # 58 = 0x3A
    bc 0) { n%3A ; n/=3A }" |
    tac |
    while read n
    do echo -n ${base58[n]}
    done
}

checksum() {
    xxd -p -r /dev/null |
    tail -c 65 |
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -binary |
    xxd -p -c 80
    )
}

```

```

$ openssl ec -pubout /dev/null | publicKeyToAddress

1GbLZiNzi7DTB4UowMuyqJw5Bh95yCbu3R

```


---

### Answer by username_2 on 2013-01-02. Score: 1

If you don't want to do it online, you can try to import the private key into Bitcoin-Qt then see if the matching public key is the one you expected.


---

### Answer by username_3 on 2012-12-10. Score: 0

My best recommendation is to try and import the private key into <https://blockchain.info/wallet/> service. This can be found under the advanced tab of the wallet. The corresponding public key will be added into your wallet for deposits.

A second option which does not require and account is to go via <https://www.bitaddress.org> and parse it with the vanity address tab.


---

### Answer by username_4 on 2013-12-01. Score: 0

The [pycoin](https://github.com/richardkiss/pycoin) Python library could be a good starting point. It has a utility that will give you the public key for a given private key. Unfortunately it doesn't seem to have a command line interface suitable for easy programmatic use.


---

