Bitcoin Forum
November 06, 2024, 02:14:05 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: how to get the missing key?  (Read 135 times)
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
April 19, 2021, 05:17:12 AM
Last edit: April 19, 2021, 07:45:03 AM by Sanka555
 #1

I am programming in Java (bitcoij library)

i have original line String="someline";

after transformations and encryptions i get correct

19SP2KEonvrYQAgk1yZ8ir9dDLq3SwXRP3 +  key1
1APDCaHFRpRi8tzHgKnzfaW3rqsxJiqDjY     + key2

its ok.

and i do
String segvit = SegwitAddress.fromKey(MainNetParams.get(), key).toBech32();
i get correct

bc1qvmk80pd2uet0zdgf4sqjlumup7f68225esv2v2    

how do i get key3?
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7362


Top Crypto Casino


View Profile WWW
April 19, 2021, 06:54:18 AM
 #2

I'm assuming you want to get the bech32 address from the public key hash?

Then you just import the org.bitcoinj.core.SegwitAddress class and call its toBech32() method like this:

Code:
SegwitAddress segwitAddress = SegwitAddress.fromHash(MainNetParams.get(), hash160); 
segwitAddress.toBech32();

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
April 19, 2021, 07:17:32 AM
Last edit: April 19, 2021, 07:30:51 AM by Sanka555
 #3

Yes. that's what I do.
Quote
key = ECKey.fromPrivate(bigInteger, true);
String segvit = SegwitAddress.fromKey(MainNetParams.get(), key).toBech32();

And now I need a key to this address.

The key, that I can enter into bitcoin core, and Core will give to me bc1qvmk80pd2uet0zdgf4sqjlumup7f68225esv2v2

if i use "key" from my code i get only
19SP2KEonvrYQAgk1yZ8ir9dDLq3SwXRP3   
or
1APDCaHFRpRi8tzHgKnzfaW3rqsxJiqDjY     
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7362


Top Crypto Casino


View Profile WWW
April 19, 2021, 08:01:13 AM
 #4

Yes. that's what I do.
Quote
key = ECKey.fromPrivate(bigInteger, true);
String segvit = SegwitAddress.fromKey(MainNetParams.get(), key).toBech32();

And now I need a key to this address.

The key, that I can enter into bitcoin core, and Core will give to me bc1qvmk80pd2uet0zdgf4sqjlumup7f68225esv2v2

I'm having trouble following, do you want to:

- Get the private key to this bech32 address, or
- From the Bitcoin Core password, use it to find and decrypt this address in the wallet file?

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
April 19, 2021, 08:06:06 AM
 #5

 Get the private key to this bech32 address
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7362


Top Crypto Casino


View Profile WWW
April 19, 2021, 08:33:59 AM
 #6

Get the private key to this bech32 address

You can't get the private key using only an address. However, if you also have the wallet.dat file, you can use a Berkeley DB library such as Oracle's (free and OSS) to read all of the ckey (encrypted private key) or key (unencrypted) fields inside the database.

Since the "ckey" fields are encrypted and need a complex process to decrypt them, let's assume you are reading an unencrypted wallet.dat, so "key" fields only.

I'm guessing based on this post and https://github.com/bitcoin/bitcoin/blob/master/src/wallet/walletdb.cpp#L102-L115 that the "key" field's key and record is

Code:
<length of id string > | key | <length> | <public key>

and

Code:
<length of private key> | <private key> | <sha256 of private key>

So you'd read each pair of these, and then run each public key through your BitcoinJ code above to get Bech32 addresses, and see which one matches "bc1qvmk80pd2uet0zdgf4sqjlumup7f68225esv2v2", and take its associated private key.

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
April 19, 2021, 08:46:14 AM
 #7

sorry, probably my fault
English..  Undecided i am not a native speaker)

i have string "blabla..."
I use Java, myself, make a pair of address + key from a string.
i make 2 pair. "compress" and "decompress"
and i want make third pair - toBech32

but I can only get the address. I can not get the key to this address


the key from which I am making the address (compressed)
doesn't give me Bech32  if i enter this key into Core . He gives me "compressed" adress


I do not need to extract and decrypt anything from wallet.dat
I am trying to create an address myself
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7362


Top Crypto Casino


View Profile WWW
April 19, 2021, 09:04:08 AM
Merited by aliashraf (1)
 #8

i have string "blabla..."
I use Java, myself, make a pair of address + key from a string.

Ok, so you're using the string as random bytes to create the private key (basically a form of brainwallet).

So in this case you should make the key first, using this string. And then the address. I have written about this in another post:

You start with getting the private key. The double SHA256 hash of the password will give you that, and you can derive the public key from it as normal...

In Java it translates to this:

Code:
import java.security.MessageDigest;

/* ... */

String text = "blabla..."; // this is your input

// First round of SHA256
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(text.getBytes(StandardCharsets.UTF_8));
// Second round of SHA256
byte[] privatekey = digest.digest(hash);

// Get the public key HASH160 from the private key
ECKey key = ECKey.fromPrivate(privatekey);
byte[] publickeyhash = key.getPubKeyHash();

// Encode HASH160 as Bech32 address
SegwitAddress segwitAddress = SegwitAddress.fromHash(MainNetParams.get(), publickeyhash);
segwitAddress.toBech32();

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
April 19, 2021, 10:25:37 AM
 #9

i do it for  "soslsoeoeo"

and i get
bc1q7gmyvmrg2fwvyap46kztuqmg0ukvyanxcqctxl    and key = L4iHGYsgeMW5HyGXhpuzvFjESsrSAaoReb6QqreZkfVuZjSUJ4AJ

but if i give this key  Electrum or https://www.blockchain.com/  wallet   i dont get  bc1q7gmyvmrg2fwvyap46kztuqmg0ukvyanxcqctxl

i get 1KqcH1oRstqekPXbwhtikewr9XRXD4tXMs

how can i get  bc1q7gmyvmrg2fwvyap46kztuqmg0ukvyanxcqctxl in wallet??



what am I doing wrong? Thanks in advance for your patience Smiley

Quote
MessageDigest digest;
         try {
            digest = MessageDigest.getInstance("SHA-256");
      
         byte[] hash = digest.digest(str.getBytes(StandardCharsets.UTF_8));
         byte[] privatekey = digest.digest(hash);
            key = ECKey.fromPrivate(privatekey);
         byte[] publickeyhash = key.getPubKeyHash();
         SegwitAddress segwitAddress = SegwitAddress.fromHash(MainNetParams.get(), publickeyhash);
         segwitAddress.toBech32();
         System.out.println(segwitAddress.toBech32() +" "+ key.getPrivateKeyAsWiF(MainNetParams.get()));

Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
April 19, 2021, 11:07:39 AM
 #10

This is my small mistake.

Thank you very much everyone. Through joint efforts, this issue was successfully resolved.
Thank you so much!
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!