<blockquote>
  <p>It seems that #1 is correct and not #2.</p>
</blockquote>

<p>Yes, #1 is correct. The encoder will add the <code>01</code> flag byte to the end of the private key for you. By doing that manually in #2, you will result in the private key having an additional byte which is incorrect.</p>

CC BY-SA 3.0
2018-01-10T03:37:54.017Z
2018-01-10T03:37:54.017Z
Ava Chow
<p>This is how we can find the WIF from a private key:</p>

<pre><code>private_key = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
decoded_private_key = bitcoin.decode_privkey(private_key, 'hex')
wif = bitcoin.encode_privkey(decoded_private_key, 'wif')
# 5HpHgWkLaovGWySEFpng1XQ6pdG1TzNWR7SrETvfTRVdKHNXZh8
</code></pre>

<p>But how to get the WIF compressed?</p>

<p>Should I do:</p>

<pre><code>private_key = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
compressed_private_key = private_key + '01'
wifcomp1 = bitcoin.encode_privkey(bitcoin.decode_privkey(private_key, 'hex'), \
             'wif_compressed')
# KwDidQJHSE67VJ6MWRvbBKAxhD3F48DvqRT6JRqrjd7MHLBjGF7V
</code></pre>

<p>or </p>

<pre><code>wifcomp2 = bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), \ 
            'wif_compressed')
# KwFfpDsaF7yxCELuyrH9gP5XL7TAt5b9HPWC1xCQbmrxfFzfMakg
</code></pre>

<p>It seems that #1 is correct and not #2.</p>

<hr>

<p>Also it seems that:</p>

<ul>
<li><p>the non-compressed WIF, imported in Electrum, produces finally a non-compressed Base58 address, </p></li>
<li><p>the compressed WIF, imported in Electrum, produces finally a compressed Base58 address</p></li>
</ul>

<p>which seems obvious. But I'd like to be sure that compression of WIF and compression of addresses at the end is really linked.</p>

<p>Can we conclude that the use of a compressed or non-compressed WIF (both encoding the same private key) will determine, when importing them in Electrum, if the public-key (and thus the address eventually) will finally be compressed or non-compressed?</p>

CC BY-SA 3.0
2018-01-10T02:48:36.963Z
[This](https://bitcoin.stackexchange.com/a/43092/52683) answers the second part of the question: "[WIF compressed key] are not *compressed private keys*. *They are private keys with a marker that indicates that their corresponding public should be compressed.* That extra marker takes an extra byte."
Basj
<wallet><private-key><wallet-import-format>
Private key to WIF compressed: which one is correct?
Basj
# Private key to WIF compressed: which one is correct?

(Asked by: username_0 on 2018-01-10)

This is how we can find the WIF from a private key:

```
private_key = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
decoded_private_key = bitcoin.decode_privkey(private_key, 'hex')
wif = bitcoin.encode_privkey(decoded_private_key, 'wif')
# 5HpHgWkLaovGWySEFpng1XQ6pdG1TzNWR7SrETvfTRVdKHNXZh8

```

But how to get the WIF compressed?

Should I do:

```
private_key = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
compressed_private_key = private_key + '01'
wifcomp1 = bitcoin.encode_privkey(bitcoin.decode_privkey(private_key, 'hex'), \
             'wif_compressed')
# KwDidQJHSE67VJ6MWRvbBKAxhD3F48DvqRT6JRqrjd7MHLBjGF7V

```

or

```
wifcomp2 = bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), \ 
            'wif_compressed')
# KwFfpDsaF7yxCELuyrH9gP5XL7TAt5b9HPWC1xCQbmrxfFzfMakg

```

It seems that #1 is correct and not #2.

---

Also it seems that:

* the non-compressed WIF, imported in Electrum, produces finally a non-compressed Base58 address,
* the compressed WIF, imported in Electrum, produces finally a compressed Base58 address

which seems obvious. But I'd like to be sure that compression of WIF and compression of addresses at the end is really linked.

Can we conclude that the use of a compressed or non-compressed WIF (both encoding the same private key) will determine, when importing them in Electrum, if the public-key (and thus the address eventually) will finally be compressed or non-compressed?

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

> **Comments:**
> **username_0**: [This](https://bitcoin.stackexchange.com/a/43092/52683) answers the second part of the question: "[WIF compressed key] are not *compressed private keys*. *They are private keys with a marker that indicates that their corresponding public should be compressed.* That extra marker takes an extra byte."  

---

## 1 answers

### Answer by username_1 on 2018-01-10. Score: 3 | Accepted answer

> It seems that #1 is correct and not #2.

Yes, #1 is correct. The encoder will add the `01` flag byte to the end of the private key for you. By doing that manually in #2, you will result in the private key having an additional byte which is incorrect.


---

