https://en.bitcoin.it/wiki/Wallet_import_formatTrying to follow this example here to do this in PHP, but I get stuck at step 3.
I can't seem to get the same SHA256 hash.
I take the extended key from step 2 "800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"
and SHA256 it.
I should get "8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592" according to step 3 but I just get "E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09"
What am I doing wrong?
As with everyone who comes here asking this question (I think this is the fifth time I've answered it, and I'm sure others have answered it many times as well), you are hashing the string (an ASCII representation of a hex number) instead of the actual hex number itself.
Awesome! Thanks!
I've got it working near perfectly, now. The only issue is that it's messing up on the final character.
Do you by chance know PHP?
$keyHex = $argv[1];
$alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
$exKey = '80' . $keyHex;
$chksum = substr(strtoupper(hash('sha256', hex2bin(strtoupper(hash('sha256', hex2bin($exKey)))))), 0, 8);
echo "Checksum: " . $chksum . "\n";
$divmod = array(gmp_init($exKey . $chksum, 16), 0);
$out = "";
while (gmp_strval($divmod[0]) >= 58)
{
$divmod = divmod($divmod[0], 58);
$out = $alphabet[gmp_strval($divmod[1])] . $out;
}
echo $out . "\n";
function divmod($x, $y)
{
$div = gmp_div($x, $y);
$mod = gmp_mod($x, $y);
return array($div, $mod);
}
If I plug in "0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D", it outputs "HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ", but it should be outputting "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" (note the prepending 5)