<p>You need to use the decode flag <code>-d</code>:</p>

<pre><code>printf "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" | base58 -c -d | xxd -p
800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d
72aa1d
</code></pre>

<p>To have <code>xxd</code> output all on one line, give it a large column number <code>-c</code> flag:</p>

<pre><code>$ printf "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" | base58 -c -d | xxd -p -c 1000
800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
</code></pre>

<p>If you really want the checksum included <code>507A5B8D</code> (the last 4 bytes), omit the <code>-c</code> flag which denotes checksum encoding:</p>

<pre><code>$ printf "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" | base58 -d | xxd -p -c 1000
800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d
</code></pre>

CC BY-SA 4.0
2019-01-22T14:19:57.377Z
2019-01-22T14:19:57.377Z
JBaczuk
<p>Here's a full script which reads the key from standard input so it doesn't get stored in a file or command history, verifies the checksum and key length, and then prints the network byte, secret key, and compressed key flag.</p>
<p>Requires <a href="https://github.com/keis/base58" rel="nofollow noreferrer">base58</a> package to be installed.</p>
<pre><code>#!/bin/bash
read -p &quot;Enter WIF key: &quot; wif_key
decoded_key=$(echo &quot;$wif_key&quot; | base58 -dc | xxd -p -c 256)
if [ ! -z $decoded_key ]
then
    keylen=$(echo -n $decoded_key | wc -c)
    if [ &quot;$keylen&quot; -ge 66 ] &amp;&amp; [ &quot;$keylen&quot; -le 68 ]
    then
        echo &quot;Network byte: ${decoded_key:0:2}&quot;;
        echo &quot;Secret key: ${decoded_key:2:64}&quot;;
        if [ -z ${decoded_key:66:2} ]; then cpk=&quot;false&quot;; else cpk=&quot;true&quot;; fi
        echo &quot;Compressed public key: $cpk&quot;;
    else
        echo &quot;Invalid decoded key length&quot; &gt;&amp;2
        $(exit 1)
    fi
else
    $(exit 1)
fi
</code></pre>
<h3>Example</h3>
<p>Prompt:</p>
<pre><code>Enter WIF key: 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
</code></pre>
<p>Output:</p>
<pre><code>Network byte: 80
Secret key: 0c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
Compressed public key: false
</code></pre>

CC BY-SA 4.0
2022-10-31T22:12:29.943Z
2022-11-01T10:43:16.377Z
2022-11-01T10:43:16.377Z
bca-0353f40e
<p>I want to convert wif as Base58 string to byte array.</p>

<p>Private key to WIF </p>

<pre><code>printf 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D | xxd -r -p | base58
</code></pre>

<blockquote>
  <p>5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ</p>
</blockquote>

<p>Now I want reverse this (WIF to private key), form <code>5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ</code> to <code>800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D</code></p>

<p>Im using that library <a href="https://github.com/keis/base58" rel="nofollow noreferrer">https://github.com/keis/base58</a> But I can change or better if I can use only bash without extra library</p>

<p>full example <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Wallet_import_format</a></p>

CC BY-SA 4.0
2019-01-22T13:29:34.293Z
Are you looking for an alternative tool to decode base58 to hex?
James C.
CC BY-SA 4.0
2019-01-22T13:55:11.537Z
no the alternative. with this tool I can't to  base58 to hex, or I don't understand How can I that
monkeyUser
<private-key><wallet-import-format><bash>
Converting WIF as Base58 string to byte array in bash
monkeyUser
# Converting WIF as Base58 string to byte array in bash

(Asked by: username_0 on 2019-01-22)

I want to convert wif as Base58 string to byte array.

Private key to WIF

```
printf 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D | xxd -r -p | base58

```

> 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ

Now I want reverse this (WIF to private key), form `5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ` to `800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D`

Im using that library <https://github.com/keis/base58> But I can change or better if I can use only bash without extra library

full example <https://en.bitcoin.it/wiki/Wallet_import_format>

**Tags:** private-key, wallet-import-format, bash

> **Comments:**
> **username_1**: Are you looking for an alternative tool to decode base58 to hex?  
> **username_0**: no the alternative. with this tool I can't to  base58 to hex, or I don't understand How can I that  

---

## 2 answers

### Answer by username_2 on 2019-01-22. Score: 1 | Accepted answer

You need to use the decode flag `-d`:

```
printf "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" | base58 -c -d | xxd -p
800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d
72aa1d

```

To have `xxd` output all on one line, give it a large column number `-c` flag:

```
$ printf "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" | base58 -c -d | xxd -p -c 1000
800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d

```

If you really want the checksum included `507A5B8D` (the last 4 bytes), omit the `-c` flag which denotes checksum encoding:

```
$ printf "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" | base58 -d | xxd -p -c 1000
800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d

```


---

### Answer by username_3 on 2022-10-31. Score: 0

Here's a full script which reads the key from standard input so it doesn't get stored in a file or command history, verifies the checksum and key length, and then prints the network byte, secret key, and compressed key flag.

Requires [base58](https://github.com/keis/base58) package to be installed.

```
#!/bin/bash
read -p "Enter WIF key: " wif_key
decoded_key=$(echo "$wif_key" | base58 -dc | xxd -p -c 256)
if [ ! -z $decoded_key ]
then
    keylen=$(echo -n $decoded_key | wc -c)
    if [ "$keylen" -ge 66 ] && [ "$keylen" -le 68 ]
    then
        echo "Network byte: ${decoded_key:0:2}";
        echo "Secret key: ${decoded_key:2:64}";
        if [ -z ${decoded_key:66:2} ]; then cpk="false"; else cpk="true"; fi
        echo "Compressed public key: $cpk";
    else
        echo "Invalid decoded key length" >&2
        $(exit 1)
    fi
else
    $(exit 1)
fi

```

### Example

Prompt:

```
Enter WIF key: 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ

```

Output:

```
Network byte: 80
Secret key: 0c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
Compressed public key: false

```


---

