6

Private Key: 9ccbcabf23e271183dbed503b43277f4c6eee9ac918cd6cda75ebb73ceb35c7d

Corresponding Public Address: 0xa73Fb234B1773ed7b115D18A1f0a15579bA2C1e1 (check for yourself on MyCrypto, for example)

One can generate the Public Key from the Private Key: 25b867253fe38ac7ed594f54b4f55fa18c49ced332fc352991e48a77ab7816c759d46cab51a59d9833cd6d958cc752ad95f10bbe469b364db2de5d3535417966

This Public Key, however, does not seem to be produce the Public Address above. Instead, after running it through keccak256, then taking the last 20 bytes, we're left with: 0xaa72e09d258da5496a7e6628e09207ec382e478a

What am I doing wrong?

3

You need to hash the bytes of the public key (not the public key string).

In Javascript https://runkit.com/embed/2w4f7dvkz2lg

keccak256 = require('js-sha3').keccak256;

keccak256(new Buffer('25b867253fe38ac7ed594f54b4f55fa18c49ced332fc352991e48a77ab7816c759d46cab51a59d9833cd6d958cc752ad95f10bbe469b364db2de5d3535417966', 'hex')).slice(24)

"a73fb234b1773ed7b115d18a1f0a15579ba2c1e1"

Note how the public key is put in a Buffer.

  • Thanks. I'm not working with Javascript, so this is the problem. Looks like my keccak algorithm will only accept strings. Oy. – EvilJordan Feb 18 '18 at 9:06
  • If it's not obvious, I'm using PHP. Groan, I know. I can turn the produced Public Key in to its bytes, and confirm they match what JS libraries are seeing. So, now to pass those bytes to the hashing algorithm in a way that is acceptable, since it will only handle strings. I've attempted to simply "implode" the byte array in to a long string, but that didn't work. Any clever ideas? – EvilJordan Feb 18 '18 at 9:36
  • 2
    Holy sweet god I got it. Just hex2bin($publicKey) before passing it in to the hash. Praise the lord. Thank you. – EvilJordan Feb 18 '18 at 10:01
  • @EvilJordan Feel free to post your own (PHP) answer also. (It was not obvious at all that you were using PHP.) – eth Feb 28 '18 at 6:17
  • @EvilJordan Thank you! I could kiss your feet right now lol. I have been trying to figure out exactly the same thing for 2 days – Zappa Mar 31 '18 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.