<p>The following python code should work. Transform the private key to HEX, and use it:</p>

<pre><code>import binascii, hashlib
def privateKey_to_WIF(pk): #wallet import format ==&gt; pra importar nas carteiras

    privWIF1 = hashlib.sha256(binascii.unhexlify('80'+pk)).hexdigest()
    privWIF2 = hashlib.sha256(binascii.unhexlify(privWIF1)).hexdigest()
    privWIF3 = '80'+pk+privWIF2[:8]

    pubnum = int(privWIF3,16)
    pubnumlist = []
    while pubnum!=0: pubnumlist.append(pubnum%58); pubnum/=58
    WIF = ''
    for l in ['123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'[x] for x in pubnumlist]:
        WIF=l+WIF
    #print WIF
    return WIF
</code></pre>

<p>It will return the Wallet Import Format which can be used in another client.</p>

<p>Example:</p>

<p>Private key WIF: 5KNjwhPMnXbFS7bVeHEzpE4He6jkQeRF9wtBtr1p1anH25rDnys</p>

CC BY-SA 3.0
2016-03-25T05:11:11.160Z
I had to convert my 64-bit base64 to 64-bit hex before feeding into this function. Then it produced a very long private key, 95 characters starting with 2H instead of 51 like in your example. This key, once imported to electrum wallet, shows a balance of 0 at the address 1LDZ8Z3Cjh6tn4xfR65Tw9wxjNap69nzjp while the address (according to the email) should be 158fiVvrKfRJzA4DLEo2fkQh4DdpBCHTrU with a balance of 23.971mBTC. I'm a bit worried that you are providing a general solution for converting private key to WIF format without regard to the special case in question (64-bitness of the key)
Tankman六四
CC BY-SA 3.0
2016-03-25T22:16:23.213Z
Zhang Weimu, try this: "pk = hashlib.sha256("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789").hexdigest()" and use it in the above code... with this sample string, I get: Private key: b49c0a968de2df1367dfd9301a26b9fdbc5db0bfe892f453f2e0156873f8ef74
Private key WIF: 5KBq1WwaHRSUcJwB5wAycR8C37TaFFNpMYsLL25gECoVoKeo9sa
Address: 12BgTfZUgoC8FAMZSVSo1ZXbMbbtLohpkz
anonimou
CC BY-SA 3.0
2016-03-25T22:17:52.040Z
note that with the above code (in the comment), the private key is not what you have, but a "seed" to the private key.. let me know if that worked out!
anonimou
CC BY-SA 3.0
2016-03-23T16:11:42.420Z
2016-03-23T16:19:34.203Z
2016-03-23T16:19:34.203Z
anonimou
<p>Taking into account that 64bytes keys are probably seed keys in bip32 format you might need to derive the key first. I modified the code to reflect that </p>

<pre><code>npm install coinstring hdkey
node 
var HDKey = require('hdkey')
var cs = require('coinstring')

// This is your base64 key 
var seed = 'oMQqnDrGq/K6aplGroOvGPUb8cn6fazEySUTzE3QFYNDQcd13NTA+sc1R8VmLYGp6TYaCqxgSnOjIb2RA7zorw=='
var hdkey = HDKey.fromMasterSeed(new Buffer(seed, 'base64'))

var hex = hdkey.privateKey
var version = 0x80; //Bitcoin private key
console.log(cs.encode(hex, version)) 
</code></pre>

<p>It should give you the familiar WIF format private key.</p>

<p>5HyfJgfUm7WVgUrLuo9uwtJR6ME7MYfGRhK2aeckZRooSKYGXP8</p>

CC BY-SA 3.0
2016-03-25T05:14:45.010Z
It writes a very long private key to the console, 95 characters starting with 2H instead of 5H like in your example. This key, once imported to electrum wallet, shows a balance of 0 at the address 1LDZ8Z3Cjh6tn4xfR65Tw9wxjNap69nzjp while the address (according to the email) should be 158fiVvrKfRJzA4DLEo2fkQh4DdpBCHTrU with a balance of 23.971mBTC. I'm a bit worried that you provided a general solution for converting private key to WIF format without regard to the special case in question (64-bitness of the key)?
Tankman六四
CC BY-SA 3.0
2016-03-26T20:58:45.877Z
In the question you mention that the key is  64 bytes, (512 bits). Here you say it is 64 bits. Can you clarify what is your situation?. You are right I wrote the first script thinking of regular private keys. This script however should work with bip32 private keys. And the first derivation should be  the one from your address.
galileopy
CC BY-SA 3.0
2016-03-22T01:10:35.703Z
2016-03-29T19:48:49.760Z
2016-03-29T19:48:49.760Z
galileopy
<p>It seems this address has not been claimed yet, and it's value went from 10usd to upwards of 1000usd with the recent rise.</p>
<p>I suspect the address you are looking for is compressed address and you were using code to get uncompressed addresses. The same private key will yield a very different compressed and uncompressed address.</p>
<p>Otherwise the Answers already provided seem pretty good. I found a good pair of payes at gobittest(dot)appspot(dot)com/PrivateKey that can convert the Hex key into WIF format and iancoleman(dot)io/bitcoin-key-compression will give you both addresses with the WIF private key.</p>
<p>Please be careful and use both webpages offline for your own safety!</p>
<p>Can you provide more information on what the resulted decoded base64 string looks like? is it a set of 32 hex characters? (0-9A-F) ?</p>

CC BY-SA 4.0
2021-02-10T02:55:58.620Z
2021-02-10T02:55:58.620Z
Kryztoval
<p>Private keys are 256 bits (32-bytes) long, according to bitcoin wiki:
<a href="https://en.bitcoin.it/wiki/Private_key" rel="nofollow">https://en.bitcoin.it/wiki/Private_key</a></p>

<p>Diamond Circle, an Australian startup, sent me a pair of bitcoin address and its private key. Blockchain.info shows that the money is still in the given address.</p>

<p>The problem is that the private key is <strong>64-bytes</strong> long. It's base-64 encoded evident by the trailing ==</p>

<p>Since it's not in WIF, I wonder how to import it. Has anyone seen 64bit private keys before?</p>

CC BY-SA 3.0
2016-03-26T06:44:37.547Z
Is it base64 encoded or hexadecimal? In base64 a private key would be around 44 characters. A private key is certainly not 32 bit, 64 bit or 64 bytes; they are 256 bits, which can be encoded as 64 characters in hexadecimal without compression flag.
Pieter Wuille
<private-key>
How to import a 64-byte long private key
Tankman六四
# How to import a 64-byte long private key

(Asked by: username_0 on 2016-03-21)

Private keys are 256 bits (32-bytes) long, according to bitcoin wiki:
<https://en.bitcoin.it/wiki/Private_key>

Diamond Circle, an Australian startup, sent me a pair of bitcoin address and its private key. Blockchain.info shows that the money is still in the given address.

The problem is that the private key is **64-bytes** long. It's base-64 encoded evident by the trailing ==

Since it's not in WIF, I wonder how to import it. Has anyone seen 64bit private keys before?

**Tags:** private-key

> **Comments:**
> **username_1**: Is it base64 encoded or hexadecimal? In base64 a private key would be around 44 characters. A private key is certainly not 32 bit, 64 bit or 64 bytes; they are 256 bits, which can be encoded as 64 characters in hexadecimal without compression flag.  

---

## 3 answers

### Answer by username_2 on 2016-03-23. Score: 1

The following python code should work. Transform the private key to HEX, and use it:

```
import binascii, hashlib
def privateKey_to_WIF(pk): #wallet import format ==> pra importar nas carteiras

    privWIF1 = hashlib.sha256(binascii.unhexlify('80'+pk)).hexdigest()
    privWIF2 = hashlib.sha256(binascii.unhexlify(privWIF1)).hexdigest()
    privWIF3 = '80'+pk+privWIF2[:8]

    pubnum = int(privWIF3,16)
    pubnumlist = []
    while pubnum!=0: pubnumlist.append(pubnum%58); pubnum/=58
    WIF = ''
    for l in ['123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'[x] for x in pubnumlist]:
        WIF=l+WIF
    #print WIF
    return WIF

```

It will return the Wallet Import Format which can be used in another client.

Example:

Private key WIF: 5KNjwhPMnXbFS7bVeHEzpE4He6jkQeRF9wtBtr1p1anH25rDnys

> **Comments:**
> **username_0**: I had to convert my 64-bit base64 to 64-bit hex before feeding into this function. Then it produced a very long private key, 95 characters starting with 2H instead of 51 like in your example. This key, once imported to electrum wallet, shows a balance of 0 at the address 1LDZ8Z3Cjh6tn4xfR65Tw9wxjNap69nzjp while the address (according to the email) should be 158fiVvrKfRJzA4DLEo2fkQh4DdpBCHTrU with a balance of 23.971mBTC. I'm a bit worried that you are providing a general solution for converting private key to WIF format without regard to the special case in question (64-bitness of the key)  
> **username_2**: Zhang Weimu, try this: "pk = hashlib.sha256("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789").hexdigest()" and use it in the above code... with this sample string, I get: Private key: b49c0a968de2df1367dfd9301a26b9fdbc5db0bfe892f453f2e0156873f8ef74 Private key WIF: 5KBq1WwaHRSUcJwB5wAycR8C37TaFFNpMYsLL25gECoVoKeo9sa Address: 12BgTfZUgoC8FAMZSVSo1ZXbMbbtLohpkz  
> **username_2**: note that with the above code (in the comment), the private key is not what you have, but a "seed" to the private key.. let me know if that worked out!  

---

### Answer by username_3 on 2016-03-22. Score: 1

Taking into account that 64bytes keys are probably seed keys in bip32 format you might need to derive the key first. I modified the code to reflect that

```
npm install coinstring hdkey
node 
var HDKey = require('hdkey')
var cs = require('coinstring')

// This is your base64 key 
var seed = 'oMQqnDrGq/K6aplGroOvGPUb8cn6fazEySUTzE3QFYNDQcd13NTA+sc1R8VmLYGp6TYaCqxgSnOjIb2RA7zorw=='
var hdkey = HDKey.fromMasterSeed(new Buffer(seed, 'base64'))

var hex = hdkey.privateKey
var version = 0x80; //Bitcoin private key
console.log(cs.encode(hex, version)) 

```

It should give you the familiar WIF format private key.

5HyfJgfUm7WVgUrLuo9uwtJR6ME7MYfGRhK2aeckZRooSKYGXP8

> **Comments:**
> **username_0**: It writes a very long private key to the console, 95 characters starting with 2H instead of 5H like in your example. This key, once imported to electrum wallet, shows a balance of 0 at the address 1LDZ8Z3Cjh6tn4xfR65Tw9wxjNap69nzjp while the address (according to the email) should be 158fiVvrKfRJzA4DLEo2fkQh4DdpBCHTrU with a balance of 23.971mBTC. I'm a bit worried that you provided a general solution for converting private key to WIF format without regard to the special case in question (64-bitness of the key)?  
> **username_3**: In the question you mention that the key is  64 bytes, (512 bits). Here you say it is 64 bits. Can you clarify what is your situation?. You are right I wrote the first script thinking of regular private keys. This script however should work with bip32 private keys. And the first derivation should be  the one from your address.  

---

### Answer by username_4 on 2021-02-10. Score: 0

It seems this address has not been claimed yet, and it's value went from 10usd to upwards of 1000usd with the recent rise.

I suspect the address you are looking for is compressed address and you were using code to get uncompressed addresses. The same private key will yield a very different compressed and uncompressed address.

Otherwise the Answers already provided seem pretty good. I found a good pair of payes at gobittest(dot)appspot(dot)com/PrivateKey that can convert the Hex key into WIF format and iancoleman(dot)io/bitcoin-key-compression will give you both addresses with the WIF private key.

Please be careful and use both webpages offline for your own safety!

Can you provide more information on what the resulted decoded base64 string looks like? is it a set of 32 hex characters? (0-9A-F) ?


---

