Bitcoin Forum
May 21, 2024, 11:57:42 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: difference legacy address from new  (Read 102 times)
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
March 06, 2021, 07:49:39 AM
Merited by o_e_l_e_o (2), vapourminer (1)
 #1

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.
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10572



View Profile
March 06, 2021, 08:41:39 AM
Merited by o_e_l_e_o (2)
 #2

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:
04934DB732D038A0FBB289C16EC37D15F0BE9562A14623F07F23A9FED2A932054C81F36B15011CAFF1B2635201A92B51D1A5532A5DCDFAFBE47C5305E36C5FDD4D
address:
1BqQfcTuvW6enmrt9eYYBNdC3ekhkNMsTS
Compressed:
Code:
pubkey:
03934DB732D038A0FBB289C16EC37D15F0BE9562A14623F07F23A9FED2A932054C
address:
13F4b5umPPVem8YfTAEtbnexFkEwKVQrcU

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
March 06, 2021, 09:22:54 AM
 #3

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
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18565


View Profile
March 06, 2021, 09:53:51 AM
 #4

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
Uncompressed - 04934db732d038a0fbb289c16ec37d15f0be9562a14623f07f23a9fed2a932054c81f36b15011caff1b2635201a92b51d1a5532a5dcdfafbe47c5305e36c5fdd4d

The compressed public key gives address 13F4b5umPPVem8YfTAEtbnexFkEwKVQrcU, while the uncompressed one gives address 1BqQfcTuvW6enmrt9eYYBNdC3ekhkNMsTS.
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
March 06, 2021, 11:05:14 AM
 #5

thank you so much. You helped me a lot)

 Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!