<p>A few things to check:</p>

<ol>
<li>Make sure you are computing the <code>HASH256</code> on the decoded byte values of the string. In other words, <code>HASH256(0x73656e646572)</code></li>
<li>Make sure you are doing 2 rounds of <code>SHA256</code></li>
<li>Using secp256k1 to generate a compressed public key</li>
<li>This is a <code>P2PKH</code> address (prefix is 1) so the steps to generate the address from the public key are:

<ol>
<li><code>pubkeyhash = HASH160(compressed pubkey)</code> i.e.<code>RIPEMD160(SHA256(compressed pubkey)</code></li>
<li>prepend <code>00</code> byte prefix for <code>P2PKH</code></li>
<li><code>BASE58CHECK(pubkeyhash)</code></li>
</ol></li>
</ol>



<pre><code>$ echo -n sender | openssl sha256
(stdin)= 0a367b92cf0b037dfd89960ee832d56f7fc151681bb41e53690e776f5786998a

$ echo 0a367b92cf0b037dfd89960ee832d56f7fc151681bb41e53690e776f5786998a | xxd -r -p | openssl sha256
(stdin)= 098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7

$ openssl ec -inform DER -text -noout -in &lt;(cat &lt;(echo -n "302e0201010420") &lt;(echo -n "098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7") &lt;(echo -n "a00706052b8104000a") | xxd -r -p) 2&gt;/dev/null | tail -6 | head -5 | sed 's/[ :]//g' | tr -d '\n' &amp;&amp; echo
04f4e5977bcb050452289ebc750b56be65086bfdf3411bb9c346430716545d66b8dede7516256f34fa362b10b3ec85ccdf58c25733e00e5d33120fb66a79e596f6

# result is even (ends in 0xf6) so prefix first 32 bytes with 02 (for odd use 03)
$ echo 02f4e5977bcb050452289ebc750b56be65086bfdf3411bb9c346430716545d66b8 | xxd -r -p | openssl sha256
(stdin)= cb59a26ae2e385719a66f568476bace40a8789c5fe91d74be6381e29feb20ecb

$ echo cb59a26ae2e385719a66f568476bace40a8789c5fe91d74be6381e29feb20ecb | xxd -r -p | openssl ripemd160
(stdin)= 53178717ab3d70c50fe8ec8598a9c2a8a703abc5

$ echo 0053178717ab3d70c50fe8ec8598a9c2a8a703abc5 | xxd -r -p | base58 -c &amp;&amp; echo
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
</code></pre>

<p>using <a href="https://github.com/keis/base58" rel="nofollow noreferrer">base58</a></p>

CC BY-SA 4.0
2019-03-08T22:34:46.577Z
Your second command is missing `| openssl sha256` and output; you can combine the first two and save `xxd` with `echo -n sender | openssl sha256 -binary | openssl sha256` and similarly for the two from pubkey to address. Instead of `cat` with three `<(echo)` you can do one `echo` -- or one herestring: `-in <(xxd -r -p <<<"hexprefix""hexprivkey""hexsuffix")`
dave_thompson_085
CC BY-SA 4.0
2019-03-06T15:19:25.260Z
2019-03-08T23:04:03.957Z
2019-03-08T23:04:03.957Z
JBaczuk
<p><code>% echo -n "sender" | bx base16-encode | bx sha256 | bx sha256 | bx ec-to-public | bx ec-to-address -v 0</code></p>

<p><strong>18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1</strong></p>

<p><code>% echo -n "sender" | bx base16-encode | bx sha256 | bx ec-to-public | bx ec-to-address -v 0</code></p>

<p><strong>1DcTtaa37w971TmoafPpE9Pk16xc42YA87</strong></p>

CC BY-SA 4.0
2019-03-07T05:03:52.517Z
2019-03-07T05:03:52.517Z
skaht
<pre><code>static void test ( )
{
  const MyByteArray x ( QByteArray ( "sender" ) );
  _trace ( x.sha256  ( ).getAddressHashCompressed ( ).toString ( ) );
  _trace ( x.sha256d ( ).getAddressHashCompressed ( ).toString ( ) );
}
</code></pre>

<p>the output is:</p>

<pre><code>1DcTtaa37w971TmoafPpE9Pk16xc42YA87
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1
</code></pre>

<p>So, your code runs sha256 only once, but not twice</p>

CC BY-SA 4.0
2019-03-06T15:09:32.093Z
2019-03-06T15:09:32.093Z
amaclin
<p>The writer of this article <a href="https://pastebin.com/raw/jCDFcESz" rel="nofollow noreferrer">https://pastebin.com/raw/jCDFcESz</a> explains that </p>

<p><code>Sha256('sender') x 2</code>  yields the address    <code>18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1</code></p>

<p>I am however getting the address <code>1DcTtaa37w971TmoafPpE9Pk16xc42YA87</code></p>

<p>What am I doing wrong?</p>

CC BY-SA 4.0
2019-03-06T14:43:15.963Z
Please post your code; it's hard to guess what the problem might be just by looking at the output.
Nate Eldredge
<address-generation><sha256>
Repeated sha256 on brain wallet
anthonyms
# Repeated sha256 on brain wallet

(Asked by: username_0 on 2019-03-06)

The writer of this article <https://pastebin.com/raw/jCDFcESz> explains that

`Sha256('sender') x 2` yields the address `18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1`

I am however getting the address `1DcTtaa37w971TmoafPpE9Pk16xc42YA87`

What am I doing wrong?

**Tags:** address-generation, sha256

> **Comments:**
> **username_1**: Please post your code; it's hard to guess what the problem might be just by looking at the output.  

---

## 3 answers

### Answer by username_2 on 2019-03-06. Score: 3 | Accepted answer

A few things to check:

1. Make sure you are computing the `HASH256` on the decoded byte values of the string. In other words, `HASH256(0x73656e646572)`
2. Make sure you are doing 2 rounds of `SHA256`
3. Using secp256k1 to generate a compressed public key
4. This is a `P2PKH` address (prefix is 1) so the steps to generate the address from the public key are:
   1. `pubkeyhash = HASH160(compressed pubkey)` i.e.`RIPEMD160(SHA256(compressed pubkey)`
   2. prepend `00` byte prefix for `P2PKH`
   3. `BASE58CHECK(pubkeyhash)`

```
$ echo -n sender | openssl sha256
(stdin)= 0a367b92cf0b037dfd89960ee832d56f7fc151681bb41e53690e776f5786998a

$ echo 0a367b92cf0b037dfd89960ee832d56f7fc151681bb41e53690e776f5786998a | xxd -r -p | openssl sha256
(stdin)= 098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7

$ openssl ec -inform DER -text -noout -in <(cat <(echo -n "302e0201010420") <(echo -n "098f6d68ce86adb2d8ba672a06227f7d177baca3568092e4cda159acca5eb0c7") <(echo -n "a00706052b8104000a") | xxd -r -p) 2>/dev/null | tail -6 | head -5 | sed 's/[ :]//g' | tr -d '\n' && echo
04f4e5977bcb050452289ebc750b56be65086bfdf3411bb9c346430716545d66b8dede7516256f34fa362b10b3ec85ccdf58c25733e00e5d33120fb66a79e596f6

# result is even (ends in 0xf6) so prefix first 32 bytes with 02 (for odd use 03)
$ echo 02f4e5977bcb050452289ebc750b56be65086bfdf3411bb9c346430716545d66b8 | xxd -r -p | openssl sha256
(stdin)= cb59a26ae2e385719a66f568476bace40a8789c5fe91d74be6381e29feb20ecb

$ echo cb59a26ae2e385719a66f568476bace40a8789c5fe91d74be6381e29feb20ecb | xxd -r -p | openssl ripemd160
(stdin)= 53178717ab3d70c50fe8ec8598a9c2a8a703abc5

$ echo 0053178717ab3d70c50fe8ec8598a9c2a8a703abc5 | xxd -r -p | base58 -c && echo
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1

```

using [base58](https://github.com/keis/base58)

> **Comments:**
> **username_3**: Your second command is missing `| openssl sha256` and output; you can combine the first two and save `xxd` with `echo -n sender | openssl sha256 -binary | openssl sha256` and similarly for the two from pubkey to address. Instead of `cat` with three `<(echo)` you can do one `echo` -- or one herestring: `-in <(xxd -r -p <<<"hexprefix""hexprivkey""hexsuffix")`  

---

### Answer by username_4 on 2019-03-07. Score: 2

`% echo -n "sender" | bx base16-encode | bx sha256 | bx sha256 | bx ec-to-public | bx ec-to-address -v 0`

**18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1**

`% echo -n "sender" | bx base16-encode | bx sha256 | bx ec-to-public | bx ec-to-address -v 0`

**1DcTtaa37w971TmoafPpE9Pk16xc42YA87**


---

### Answer by username_5 on 2019-03-06. Score: 2

```
static void test ( )
{
  const MyByteArray x ( QByteArray ( "sender" ) );
  _trace ( x.sha256  ( ).getAddressHashCompressed ( ).toString ( ) );
  _trace ( x.sha256d ( ).getAddressHashCompressed ( ).toString ( ) );
}

```

the output is:

```
1DcTtaa37w971TmoafPpE9Pk16xc42YA87
18aMGf2AxQ3YXyNv9sKxiHYCXcBJeJv9d1

```

So, your code runs sha256 only once, but not twice


---

