Title: difference legacy address from new Post by: Sanka555 on March 06, 2021, 07:49:39 AM I am trying to create privatkey
Quote private String wizard(String input) { ECKey address = createAddress(input.getBytes()); byte[] hash160 = RIPEMD160(SHA256(address.getPubKey())); LegacyAddress legacyAddress = LegacyAddress.fromPubKeyHash(MainNetParams.get(), hash160); return legacyAddress.toBase58()+" key "+address.getPrivateKeyAsWiF(MainNetParams.get()); } get adress +private key 1BqQfcTuvW6enmrt9eYYBNdC3ekhkNMsTS key 5Jx5Uj29KvD72Yt3JmLQE9sSMc3nXQ5vTRV4ALZB351uyo2v7v9 everything works correctly. One line always gives the same address and key and if i put this key in blockchain.com i get this adress but if i try to encrypt THE SAME STRING here http://crypt-online.ru/crypts/sha256/ through SHA256 I get another privatKey 956324220c316c960c31329b6c4efbee4c30f648ed50606191e0807d9e28552a which gives me in blockchain.com a completely different adress. 13F4b5umPPVem8YfTAEtbnexFkEwKVQrcU but it must be the same key in different encoding... what am I doing wrong in code? maybe these addresses are somehow connected and I just don't understand how? my entire code is here, if needed https://bitcoin.stackexchange.com/questions/68064/how-to-get-compressed-public-key-with-eckey grateful for any help. Title: Re: difference legacy address from new Post by: pooya87 on March 06, 2021, 08:41:39 AM Private key is the same just using different encodings:
Hexadecimal: 956324220C316C960C31329B6C4EFBEE4C30F648ED50606191E0807D9E28552A Compressed base58: L2E6mNU3kVrRbqiHBQgdX49cuwhHwAtiwd4pxDK1J8j2qWkVisQX Uncompressed base58: 5Jx5Uj29KvD72Yt3JmLQE9sSMc3nXQ5vTRV4ALZB351uyo2v7v9 Compressed private key corresponds to compressed public key and similarly uncompressed private key to uncompressed public key. When creating a new address from comp/uncomp pubkey you feed a different value to the hash algorithm and get a different hash result, hence the address created from a different hash is different: Uncompressed Code: pubkey: Code: pubkey: Title: Re: difference legacy address from new Post by: Sanka555 on March 06, 2021, 09:22:54 AM I do not quite understand. : - [
What do I need to change in the code so that it gives the same address? I tried to do directly Quote private String wizard(String input) { MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8)); ECKey address = createAddress(hash); System.out.println(" key "+address.getPrivateKeyAsWiF(MainNetParams.get())); String->sha256->get.key but I get the same thing. again two different addresses Title: Re: difference legacy address from new Post by: o_e_l_e_o on March 06, 2021, 09:53:51 AM I do not quite understand. : - [ 956324220c316c960c31329b6c4efbee4c30f648ed50606191e0807d9e28552a is your raw private key in hex.5Jx5Uj29KvD72Yt3JmLQE9sSMc3nXQ5vTRV4ALZB351uyo2v7v9 is the same private key converted to Wallet Import Format (WIF). This adds a 0x80 version byte to the front, appends a checksum to the end, and converts it in to Base58. You can do this for yourself on this page: https://gobittest.appspot.com/PrivateKey These two numbers represent the same private key. When you turn a private key in to a public key, you can turn it in to two representations of the same point - one compressed, and on uncompressed. For the above private key, this gives the the following two public keys: Code: Compressed - 03934db732d038a0fbb289c16ec37d15f0be9562a14623f07f23a9fed2a932054c The compressed public key gives address 13F4b5umPPVem8YfTAEtbnexFkEwKVQrcU, while the uncompressed one gives address 1BqQfcTuvW6enmrt9eYYBNdC3ekhkNMsTS. Title: Re: difference legacy address from new Post by: Sanka555 on March 06, 2021, 11:05:14 AM thank you so much. You helped me a lot)
:) |