Title: Importing list of Hexadecimal (64 characters) Private Keys Post by: romani245 on December 02, 2017, 12:02:44 AM 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. Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: HCP on December 02, 2017, 12:14:38 PM 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 ;)
Code: import bitcoin 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 Script will output "wif_conv.txt" which will contain both the "WIF uncompressed" and "WIF compressed" representations of those hex keys: Code: 5J2gRZtwPeMHgjakdLL839Xn5pLBdNTKDBeB5uHDJTcwYaL5Tvb Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: whohackedme on June 04, 2018, 04:08:39 PM 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 Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: whohackedme on June 04, 2018, 05:55:52 PM I am missing something about the Hex format, I just cant figure out the fix.
here is my python: Code: import bitcoin 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' Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: HCP on June 04, 2018, 10:00:43 PM 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 That should generate something like this: Code: (hex2add.txt) 1c2448d1a829c3f0c363f5e1d77a72cbd85ed1e9b4405eb5c160945db3a21ba001:15LbnZxveboebARPggJxQn1c5nDVVeUCXQ Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: whohackedme on June 04, 2018, 10:31:17 PM Thank you!
Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: whohackedme on June 05, 2018, 02:17:14 AM 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 Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: HCP on June 05, 2018, 03:59:56 AM 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. huh... that's odd. That error indicates that the checksum is failing when it is checking the private key??!?... ???.... 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:] Did you run it on your keys? or just on the example ones I gave you? I don't get that error... ??? Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: whohackedme on June 18, 2018, 03:58:44 AM 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, Title: Re: Importing list of Hexadecimal (64 characters) Private Keys Post by: HCP on June 18, 2018, 11:35:08 AM 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 :P
Good to know that the script is working ok other than that minor glitch. Thanks for letting me know. :) |