Bitcoin Forum
September 21, 2019, 01:27:15 AM *
News: If you like a topic and you see an orange "bump" link, click it. More info.
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Importing list of Hexadecimal (64 characters) Private Keys  (Read 530 times)
romani245
Sr. Member
****
Offline Offline

Activity: 269
Merit: 254


View Profile
December 02, 2017, 12:02:44 AM
 #1

Hi, I need to import a list of hex private keys. I was hoping to just create a new wallet in Electrum and copy/paste the list of keys, but I guess Electrum only supports import of WIF private keys.

Rather than convert them all manually, is there a safe wallet that allows import of private key lists like Electrum, which supports hex format?

Thanks.
If you want to be a moderator, report many posts with accuracy. You will be noticed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1569029235
Hero Member
*
Offline Offline

Posts: 1569029235

View Profile Personal Message (Offline)

Ignore
1569029235
Reply with quote  #2

1569029235
Report to moderator
1569029235
Hero Member
*
Offline Offline

Posts: 1569029235

View Profile Personal Message (Offline)

Ignore
1569029235
Reply with quote  #2

1569029235
Report to moderator
HCP
Legendary
*
Offline Offline

Activity: 1092
Merit: 1793

<insert witty quote here>


View Profile
December 02, 2017, 12:14:38 PM
Merited by Welsh (3), HeRetiK (1)
 #2

I took the liberty of hacking up a small python script that will take a text file of HEX privkeys and convert it into a text file with WIF privkeys... It will convert the hex to both "uncompressed" and "compressed" WIF keys, so you shouldn't miss any addresses. So you can simply run the script and then copy/paste the WIF keys into Electrum Wink

Code:
import bitcoin

with open("hex_keys.txt","r") as f:
    content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
f.close()


outfile = open("wif_conv.txt","w")
for x in content:
  outfile.write(bitcoin.encode_privkey(x,'wif')+"\n")
  outfile.write(bitcoin.encode_privkey(x,'wif_compressed')+"\n")
 
outfile.close()


NOTES:
- You need the "bitcoin" library... ie. pip install bitcoin
- hex_keys.txt should be a text file that has one hex key per line... like this:
Code:
1c2448d1a829c3f0c363f5e1d77a72cbd85ed1e9b4405eb5c160945db3a21ba001
f9d606ff0d9474483bde36a711f1c41896122056cc7e7a23b05b3e68438165da01
a5f2143180073849ec38a4936aceecde398e031b57a17aad20194b6132d0612101
64c85fc1473a8ea297e3c65a68b9fc2a1ac64c966111f8c7d0f5abfe8b574ad501
93917a448caecfe50e0850880edea56e1e5202bfdd6a68e32e049ab535ca000f01


Script will output "wif_conv.txt" which will contain both the "WIF uncompressed" and "WIF compressed" representations of those hex keys:
Code:
5J2gRZtwPeMHgjakdLL839Xn5pLBdNTKDBeB5uHDJTcwYaL5Tvb
KxAR1SCF4wrYeNwyZNKQ4UeqzFufuXh9Nmy5WdkZJ4VdjsSM3GRv
5KiKJpBHXnRARET7KvQtYvSspTGjazcV1y4yxkbrXkSdCQL8DCR
L5bModEPxsTeZxNEvWkSXtuDJSxSy3HcfGUaR5Sqcik6kroMm4pQ
5K5NSTHgcdiizKawaczdXm7nnyWPk2seZcMpsqfGkW3peZ2rtbX
L2nHdM2drH5AL12ouPsNEmiy7vQjNwGYnw4vKPmvX1DTJKS6HVUX
5JafwWRx3dUUpX4ZFQv93DHrkKFkkyYWSWSWdRV4oZmqF3sxM6a
Kzbcsau7xbzHnjghLcZYUmFQaBa896a4wawbmm4snXesvaSMjW5e
5JwH1pa4KBjJr2zu2zCHkHQafShkQbf7kv2k3xJu2T7hTbbM9rQ
L2AZgcxudGMjmRpYfmSpv3R5agSrb9yEpq4h237zdQGZa4bvBM6t


whohackedme
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
June 04, 2018, 04:08:39 PM
 #3

HCP, Thanks for the code

I have been messing with this and decided to give up and just ask you.

Can you modify the code so the output.txt will have both the hex key & compressed address  ?

Output.tx contents would look like:

Code:
1c2448d1a829c3f0c363f5e1d77a72cbd85ed1e9b4405eb5c160945db3a21ba001:15LbnZxveboebARPggJxQn1c5nDVVeUCXQ
f9d606ff0d9474483bde36a711f1c41896122056cc7e7a23b05b3e68438165da01:1FyXSZ2D7eoYEAtSzQ5BXtD7coLsU4tuDV
a5f2143180073849ec38a4936aceecde398e031b57a17aad20194b6132d0612101:1PmuScdC33quyPjj7SC85c3bnEJJGfBkw5
64c85fc1473a8ea297e3c65a68b9fc2a1ac64c966111f8c7d0f5abfe8b574ad501:1BTcYd2Hr3urk7zJtP2jdcekUJAmpyJn8a
93917a448caecfe50e0850880edea56e1e5202bfdd6a68e32e049ab535ca000f01:19bkMCgmCCEBQQcNiDfr7QScmSGk23jyqy
whohackedme
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
June 04, 2018, 05:55:52 PM
 #4

I am missing something about the Hex format, I just cant figure out the fix.

here is my python:

Code:
import bitcoin

with open("hex_keys.txt","r") as f:
    content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
f.close()

outfile = open("hex2add.txt","w")
for x in content:
  outfile.write(bitcoi[Suspicious link removed]ivkey_to_address(x,'hex')+"\n")
  outfile.write((x)+"\n")
 
outfile.close()


I get the following error:

Traceback (most recent call last):
  File "hex2add.py", line 13, in <module>
    outfile.write(bitcoi[Suspicious link removed]ivkey_to_address(x,'hex')+"\n")
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 304, in privkey_to_address
    return pubkey_to_address(privkey_to_pubkey(priv), magicbyte)
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 451, in pubkey_to_address
    bin_hash160(binascii.unhexlify(pubkey)), magicbyte)
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/py2specials.py", line 43, in bin_to_b58check
    inp_fmtd = chr(int(magicbyte)) + inp
ValueError: invalid literal for int() with base 10: 'hex'
HCP
Legendary
*
Offline Offline

Activity: 1092
Merit: 1793

<insert witty quote here>


View Profile
June 04, 2018, 10:00:43 PM
 #5

You don't need to pass anything into the privtoaddr() function except for the private key "hex"... it doesn't need a 'format' parameter like the encode_privkey() function.

So you can just do this:
Code: (hex_to_addr.py)
import bitcoin

with open("hex_keys.txt","r") as f:
    content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
f.close()


outfile = open("hex2add.txt","w")
for x in content:
  outfile.write(x+":"+bitcoin.privtoaddr(x)+"\n")
 
outfile.close()


That should generate something like this:
Code: (hex2add.txt)
1c2448d1a829c3f0c363f5e1d77a72cbd85ed1e9b4405eb5c160945db3a21ba001:15LbnZxveboebARPggJxQn1c5nDVVeUCXQ
f9d606ff0d9474483bde36a711f1c41896122056cc7e7a23b05b3e68438165da01:1FyXSZ2D7eoYEAtSzQ5BXtD7coLsU4tuDV
a5f2143180073849ec38a4936aceecde398e031b57a17aad20194b6132d0612101:1PmuScdC33quyPjj7SC85c3bnEJJGfBkw5
64c85fc1473a8ea297e3c65a68b9fc2a1ac64c966111f8c7d0f5abfe8b574ad501:1BTcYd2Hr3urk7zJtP2jdcekUJAmpyJn8a
93917a448caecfe50e0850880edea56e1e5202bfdd6a68e32e049ab535ca000f01:19bkMCgmCCEBQQcNiDfr7QScmSGk23jyqy

whohackedme
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
June 04, 2018, 10:31:17 PM
 #6

Thank you!
whohackedme
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
June 05, 2018, 02:17:14 AM
 #7

Works great!!,  (So, it really does not matter what warnings it has)  Please let me know if there is something configured wrong on my side.

Code:
~/Documents$ python hex2add.py
Traceback (most recent call last):
  File "hex2add.py", line 12, in <module>
    outfile.write(x+":"+bitcoi[Suspicious link removed]ivtoaddr(x)+"\n")
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 304, in privkey_to_address
    return pubkey_to_address(privkey_to_pubkey(priv), magicbyte)
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 291, in privkey_to_pubkey
    f = get_privkey_format(privkey)
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 217, in get_privkey_format
    bin_p = b58check_to_bin(priv)
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 427, in b58check_to_bin
    assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]
AssertionError
~/Documents$ cat hex2add.txt
1c2448d1a829c3f0c363f5e1d77a72cbd85ed1e9b4405eb5c160945db3a21ba001:15LbnZxveboebARPggJxQn1c5nDVVeUCXQ
f9d606ff0d9474483bde36a711f1c41896122056cc7e7a23b05b3e68438165da01:1FyXSZ2D7eoYEAtSzQ5BXtD7coLsU4tuDV
a5f2143180073849ec38a4936aceecde398e031b57a17aad20194b6132d0612101:1PmuScdC33quyPjj7SC85c3bnEJJGfBkw5
64c85fc1473a8ea297e3c65a68b9fc2a1ac64c966111f8c7d0f5abfe8b574ad501:1BTcYd2Hr3urk7zJtP2jdcekUJAmpyJn8a
93917a448caecfe50e0850880edea56e1e5202bfdd6a68e32e049ab535ca000f01:19bkMCgmCCEBQQcNiDfr7QScmSGk23jyqy
~/Documents$

HCP
Legendary
*
Offline Offline

Activity: 1092
Merit: 1793

<insert witty quote here>


View Profile
June 05, 2018, 03:59:56 AM
 #8

Works great!!,  (So, it really does not matter what warnings it has)  Please let me know if there is something configured wrong on my side.

....
  File "/usr/local/lib/python2.7/dist-packages/bitcoin/main.py", line 427, in b58check_to_bin
    assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]

huh... that's odd. That error indicates that the checksum is failing when it is checking the private key??!?... Huh

Did you run it on your keys? or just on the example ones I gave you? I don't get that error... Huh

whohackedme
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
June 18, 2018, 03:58:44 AM
 #9

That code works perfect, even if the input file has 1000 keys, it converts them all in output file.

I guess there is just an error at the end of the file,
HCP
Legendary
*
Offline Offline

Activity: 1092
Merit: 1793

<insert witty quote here>


View Profile
June 18, 2018, 11:35:08 AM
 #10

Oh right... It's probably just reading a stray space or newline character or something at the end of the file and attempting to convert that into a private key Tongue

Good to know that the script is working ok other than that minor glitch. Thanks for letting me know. Smiley

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!