<p>Answer was here: <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow">https://en.bitcoin.it/wiki/Wallet_import_format</a> </p>

<p>To make brainwallet need to take a sha256 of password:</p>

<pre><code># echo -n 'yourbrainwalletpassword' | sha256sum 
8abe468e0d5a814c644d9517ae35b36666d554b7bd682fa28c39e90d0cb5f91a
</code></pre>

<p>I've write a little bash script:</p>

<pre><code>declare -a base58=(
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
)

encodeBase58() {
    dc -e "16i ${1^^} [3A ~r d0&lt;x]dsxx +f" |
    while read -r n; do echo -n "${base58[n]}"; done
}

[ -z "$1" ] &amp;&amp; echo "Usage: ./script.sh privkey" &amp;&amp; exit 1

privkey="$1"

stage12="$(echo -n "$privkey" | sed -e 's/^/80/')"
stage35="$(echo $stage12 | xxd -r -p | sha256sum | awk '{print $1}' | xxd -r -p | sha256sum | awk '{print $1}'  | cut -b 1,2,3,4,5,6,7,8)"

echo "$(encodeBase58 "${stage12}${stage35}")"
</code></pre>

<p>Use this script against sha256 sum:</p>

<pre><code># bash script.sh 8abe468e0d5a814c644d9517ae35b36666d554b7bd682fa28c39e90d0cb5f91a
5JsPbHfVB7FeD6gGWoaQv6khRsasTJDK1tAiJ4TxgyWJLcjfgNa
</code></pre>

<p>Now, I can import privkey to the <code>wallet.dat</code>:</p>

<pre><code># bitcoind importprivkey 5JsPbHfVB7FeD6gGWoaQv6khRsasTJDK1tAiJ4TxgyWJLcjfgNa "yourbrainwalletpassword" 
# bitcoind getaddressesbyaccount "yourbrainwalletpassword" 
[ 
    "1Gu3HZDq6YEXfxwDC3A3EhDfEVAeCijbEt" 
] 
</code></pre>

<p>According to wiki, there are higher and lower borders.</p>

<blockquote>
  <p>Nearly every 256-bit number is a valid private key. Specifically, any 256-bit number between 0x1 and 0xFFFF FFFF FFFF FFFF FFFF FFFF
  FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4141 is a valid private
  key.</p>
</blockquote>

<p>However, I'm successfully import priv key</p>

<pre><code>FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
</code></pre>

<p>After a while, bitcoind tell me:</p>

<pre><code>error: {"code":-1,"message":"CKey::GetPrivKey() : i2d_ECPrivateKey failed"}
</code></pre>

<p>Hope it would be helpfull.</p>

<p>Thank you !</p>

CC BY-SA 3.0
2014-01-29T02:21:42.537Z
2014-01-29T02:21:42.537Z
Anomalous Awe
<p>Is there complete solution for <strong>console</strong> to generate brain wallet? Something like:</p>

<pre><code>echo "sausage" | xxd -r -p | sha256sum | awk '{print $1}' | rmd160 -x | blablabla
</code></pre>

<p>I'm read this article: <a href="https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses" rel="noreferrer">https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses</a></p>

<p>0-1) I'm skip generation public key from private, and start with it like it was a brain wallet "sausage":</p>

<p>2) - Perform a sha256sum from pubkey:</p>

<pre><code># echo -n 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6 \
| xxd -r -p | sha256sum | awk '{print $1}' 
600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408
</code></pre>

<p>3) - Perform RIPEMD-160 hashing on the result of SHA-256: </p>

<pre><code># echo -n 600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408 \
| xxd -r -p | openssl rmd160 
010966776006953d5567439e5e39f86a0d273bee
</code></pre>

<p>4) - Add version byte in front of RIPEMD-160 hash (0x00 for Main Network) </p>

<pre><code># echo 010966776006953d5567439e5e39f86a0d273bee \ 
| sed -e 's/^/00/'  
00010966776006953d5567439e5e39f86a0d273bee
</code></pre>

<p>5) - Perform SHA-256 hash on the extended RIPEMD-160 result </p>

<pre><code># echo -n 00010966776006953D5567439E5E39F86A0D273BEE \
| xxd -r -p | sha256sum | awk '{print $1}'
445c7a8007a93d8733188288bb320a8fe2debd2ae1b47f0f50bc10bae845c094
</code></pre>

<p>6) - Perform SHA-256 hash on the result of the previous SHA-256 hash </p>

<pre><code># echo -n 445C7A8007A93D8733188288BB320A8FE2DEBD2AE1B47F0F50BC10BAE845C094 \
| xxd -r -p | sha256sum | awk '{print $1}'
d61967f63c7dd183914a4ae452c9f6ad5d462ce3d277798075b107615c1a8a30
</code></pre>

<p>7) - Take the first 4 bytes of the second SHA-256 hash. This is the address checksum </p>

<pre><code># echo d61967f63c7dd183914a4ae452c9f6ad5d462ce3d277798075b107615c1a8a30 \
| cut -b 1,2,3,4,5,6,7,8 
d61967f6
</code></pre>

<p>Am I correct?</p>

<p>8) - Add the 4 checksum bytes from stage 7 at the end of extended RIPEMD-160 hash from stage 4. This is the 25-byte binary Bitcoin Address. </p>

<p>concatenate</p>

<p>9)  - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address form</p>

<p>I'm take base58 from here: <a href="https://github.com/grondilu/bitcoin-bash-tools/blob/master/bitcoin.sh" rel="noreferrer">https://github.com/grondilu/bitcoin-bash-tools/blob/master/bitcoin.sh</a></p>

<p><hr>
The result I have is:</p>

<pre><code>declare -a base58=(
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
)

encodeBase58() {
    dc -e "16i ${1^^} [3A ~r d0&lt;x]dsxx +f" |
    while read -r n; do echo -n "${base58[n]}"; done
}
stage24="$(echo -n 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6 \
    | xxd -r -p | sha256sum | awk '{print $1}' \
    | xxd -r -p | openssl rmd160 | awk '{print $2}' \
    | sed -e 's/^/00/')"

stage57="$(echo $stage24 | xxd -r -p | sha256sum | awk '{print $1}' \
    | xxd -r -p | sha256sum | awk '{print $1}' \
    | cut -b 1,2,3,4,5,6,7,8)"

# stage 89
echo "1$(encodeBase58 "${stage24}${stage57}")"
</code></pre>

<p>Bingo!</p>

<pre><code>16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
</code></pre>

<hr>

<p>According to Wiki: en.bitcoin.it/wiki/Wallet_import_format</p>

<p>Private Key before importing must be converted the similar way:</p>

<pre><code>declare -a base58=(
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
)

encodeBase58() {
    dc -e "16i ${1^^} [3A ~r d0&lt;x]dsxx +f" |
    while read -r n; do echo -n "${base58[n]}"; done
}

stage12="$(echo -n "18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725" | sed -e 's/^/80/')"
stage35="$(echo $stage12 | xxd -r -p | sha256sum | awk '{print $1}' | xxd -r -p | sha256sum | awk '{print $1}'  | cut -b 1,2,3,4,5,6,7,8)"

echo "$(encodeBase58 "${stage12}${stage35}")"
</code></pre>

<p>Now, I still have an question: How to make brain wallet like "sausage"?</p>

CC BY-SA 3.0
2014-01-28T08:16:00.170Z
The fact that it accepts FFFF...FFFF sounds like a bug. Looking into it.
Pieter Wuille
CC BY-SA 3.0
2014-01-28T09:23:36.983Z
You are right. error: `{"code":-1,"message":"CKey::GetPrivKey() : i2d_ECPrivateKey failed"} `
Anomalous Awe
CC BY-SA 3.0
2014-01-28T09:36:31.107Z
See https://github.com/bitcoin/bitcoin/pull/3593
Pieter Wuille
CC BY-SA 3.0
2014-01-28T20:11:44.753Z
Do you know how exactly realize Step 1->2, From sha256 generate ec pubkey in `bash`?
Anomalous Awe
<address-generation><brain-wallet>
Is there a way to generate a brain wallet from the command line or console?
Anomalous Awe
# Is there a way to generate a brain wallet from the command line or console?

(Asked by: username_0 on 2014-01-28)

Is there complete solution for **console** to generate brain wallet? Something like:

```
echo "sausage" | xxd -r -p | sha256sum | awk '{print $1}' | rmd160 -x | blablabla

```

I'm read this article: <https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses>

0-1) I'm skip generation public key from private, and start with it like it was a brain wallet "sausage":

2) - Perform a sha256sum from pubkey:

```
# echo -n 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6 \
| xxd -r -p | sha256sum | awk '{print $1}' 
600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408

```

3) - Perform RIPEMD-160 hashing on the result of SHA-256:

```
# echo -n 600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408 \
| xxd -r -p | openssl rmd160 
010966776006953d5567439e5e39f86a0d273bee

```

4) - Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)

```
# echo 010966776006953d5567439e5e39f86a0d273bee \ 
| sed -e 's/^/00/'  
00010966776006953d5567439e5e39f86a0d273bee

```

5) - Perform SHA-256 hash on the extended RIPEMD-160 result

```
# echo -n 00010966776006953D5567439E5E39F86A0D273BEE \
| xxd -r -p | sha256sum | awk '{print $1}'
445c7a8007a93d8733188288bb320a8fe2debd2ae1b47f0f50bc10bae845c094

```

6) - Perform SHA-256 hash on the result of the previous SHA-256 hash

```
# echo -n 445C7A8007A93D8733188288BB320A8FE2DEBD2AE1B47F0F50BC10BAE845C094 \
| xxd -r -p | sha256sum | awk '{print $1}'
d61967f63c7dd183914a4ae452c9f6ad5d462ce3d277798075b107615c1a8a30

```

7) - Take the first 4 bytes of the second SHA-256 hash. This is the address checksum

```
# echo d61967f63c7dd183914a4ae452c9f6ad5d462ce3d277798075b107615c1a8a30 \
| cut -b 1,2,3,4,5,6,7,8 
d61967f6

```

Am I correct?

8) - Add the 4 checksum bytes from stage 7 at the end of extended RIPEMD-160 hash from stage 4. This is the 25-byte binary Bitcoin Address.

concatenate

9) - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address form

I'm take base58 from here: <https://github.com/grondilu/bitcoin-bash-tools/blob/master/bitcoin.sh>

---

The result I have is:

```
declare -a base58=(
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
)

encodeBase58() {
    dc -e "16i ${1^^} [3A ~r d0<x]dsxx +f" |
    while read -r n; do echo -n "${base58[n]}"; done
}
stage24="$(echo -n 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6 \
    | xxd -r -p | sha256sum | awk '{print $1}' \
    | xxd -r -p | openssl rmd160 | awk '{print $2}' \
    | sed -e 's/^/00/')"

stage57="$(echo $stage24 | xxd -r -p | sha256sum | awk '{print $1}' \
    | xxd -r -p | sha256sum | awk '{print $1}' \
    | cut -b 1,2,3,4,5,6,7,8)"

# stage 89
echo "1$(encodeBase58 "${stage24}${stage57}")"

```

Bingo!

```
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM

```

---

According to Wiki: en.bitcoin.it/wiki/Wallet\_import\_format

Private Key before importing must be converted the similar way:

```
declare -a base58=(
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
)

encodeBase58() {
    dc -e "16i ${1^^} [3A ~r d0<x]dsxx +f" |
    while read -r n; do echo -n "${base58[n]}"; done
}

stage12="$(echo -n "18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725" | sed -e 's/^/80/')"
stage35="$(echo $stage12 | xxd -r -p | sha256sum | awk '{print $1}' | xxd -r -p | sha256sum | awk '{print $1}'  | cut -b 1,2,3,4,5,6,7,8)"

echo "$(encodeBase58 "${stage12}${stage35}")"

```

Now, I still have an question: How to make brain wallet like "sausage"?

**Tags:** address-generation, brain-wallet

> **Comments:**
> **username_1**: The fact that it accepts FFFF...FFFF sounds like a bug. Looking into it.  
> **username_0**: You are right. error: `{"code":-1,"message":"CKey::GetPrivKey() : i2d_ECPrivateKey failed"} `  
> **username_1**: See https://github.com/bitcoin/bitcoin/pull/3593  
> **username_0**: Do you know how exactly realize Step 1->2, From sha256 generate ec pubkey in `bash`?  

---

## 1 answers

### Answer by username_0 on 2014-01-29. Score: 3

Answer was here: <https://en.bitcoin.it/wiki/Wallet_import_format>

To make brainwallet need to take a sha256 of password:

```
# echo -n 'yourbrainwalletpassword' | sha256sum 
8abe468e0d5a814c644d9517ae35b36666d554b7bd682fa28c39e90d0cb5f91a

```

I've write a little bash script:

```
declare -a base58=(
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
)

encodeBase58() {
    dc -e "16i ${1^^} [3A ~r d0<x]dsxx +f" |
    while read -r n; do echo -n "${base58[n]}"; done
}

[ -z "$1" ] && echo "Usage: ./script.sh privkey" && exit 1

privkey="$1"

stage12="$(echo -n "$privkey" | sed -e 's/^/80/')"
stage35="$(echo $stage12 | xxd -r -p | sha256sum | awk '{print $1}' | xxd -r -p | sha256sum | awk '{print $1}'  | cut -b 1,2,3,4,5,6,7,8)"

echo "$(encodeBase58 "${stage12}${stage35}")"

```

Use this script against sha256 sum:

```
# bash script.sh 8abe468e0d5a814c644d9517ae35b36666d554b7bd682fa28c39e90d0cb5f91a
5JsPbHfVB7FeD6gGWoaQv6khRsasTJDK1tAiJ4TxgyWJLcjfgNa

```

Now, I can import privkey to the `wallet.dat`:

```
# bitcoind importprivkey 5JsPbHfVB7FeD6gGWoaQv6khRsasTJDK1tAiJ4TxgyWJLcjfgNa "yourbrainwalletpassword" 
# bitcoind getaddressesbyaccount "yourbrainwalletpassword" 
[ 
    "1Gu3HZDq6YEXfxwDC3A3EhDfEVAeCijbEt" 
] 

```

According to wiki, there are higher and lower borders.

> Nearly every 256-bit number is a valid private key. Specifically, any 256-bit number between 0x1 and 0xFFFF FFFF FFFF FFFF FFFF FFFF
> FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4141 is a valid private
> key.

However, I'm successfully import priv key

```
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 

```

After a while, bitcoind tell me:

```
error: {"code":-1,"message":"CKey::GetPrivKey() : i2d_ECPrivateKey failed"}

```

Hope it would be helpfull.

Thank you !


---

