Post
Topic
Board Bitcoin Technical Support
Merits 6 from 3 users
Re: Problem with my private key
by
HCP
on 24/04/2019, 13:58:10 UTC
⭐ Merited by bones261 (3) ,AdolfinWolf (2) ,ETFbitcoin (1)
Your WIF format private key (KwFAa6AumokBD2dVqQLPou42jHiVsvThY1n25HJ8Ji8REf1wxAQb) seems to be converting to a "bad hex"... if we look at the length:
Code:
00BF9C46A7C40AAF96ED20CFC0AB0F929D9BE1748AF89B37E9EFB4CDB98DA6B0CB
123456789012345678901234567890123456789012345678901234567890123456
We can see that it is 66 characters (33 bytes) long!!?! Shocked Shocked Shocked Private keys are only supposed to be 64 characters (32 bytes) of hex!

I would guess there is an error somewhere in private key generation in your script... most likely because it doesn't include this patch from the botg.sh shell script:
0.0.3 -remake key if it's not exactly 64

I believe the exact bit of code is:
Code:
hexsize=$(openssl ec -text -noout -in data.pem | head -5 | tail -3 | fmt -120 | sed 's/[: ]//g' )

while [ ${#hexsize} -ne 64 ]
do
openssl  ecparam -genkey -name secp256k1 | tee data.pem &>/dev/null && hexsize=$(openssl ec -text -noout -in data.pem | head -5 | tail -3 | fmt -120 | sed 's/[: ]//g' )
done

openssl ec -text -noout -in data.pem | head -5 | tail -3 | fmt -120 | sed 's/[: ]//g'

It generates hex keys until it gets one that is exactly 64 chars long... this size check is NOT in that .php script... and I believe this is the likely reason why your script is generating "invalid" hex private keys and then converting them to invalid WIF keys.



Now, I know that it's a trust issue here with an exe, I don't even know if the link is not hidden by the forum.
If you PM me an e-mail I gladly post the link again (or I'll simply send it by e-mail). I can also give you the source code, it's 99% the old good "Bitcoin Address Utility", it's in c#, just ask.

Why reinvent the wheel? Huh

Once you have the "correct" hex... you can simply plug it into the "Private key to wallet import format" part of http://gobittest.appspot.com/PrivateKey or bitaddress.org (download and run offline etc)... or even the bitcoinpaperwallet.com that he was checking with will work just fine with HEX private keys...