Author

Topic: how to get the missing key? (Read 135 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
April 19, 2021, 05:33:59 AM
#10
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??

You should add prefix "p2wpkh:" when import private key for Bech32 address. However, when i tried it on Electrum 4.0.7, i got address bc1qe6366c3vxt83duagx38zrftkjqzz0u8kn6ylje instead. Something is wrong with your code.
member
Activity: 96
Merit: 36
April 19, 2021, 06: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!
member
Activity: 96
Merit: 36
April 19, 2021, 05: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()));

legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 19, 2021, 04:04:08 AM
#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();
member
Activity: 96
Merit: 36
April 19, 2021, 03: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
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 19, 2021, 03: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:
| key | |

and

Code:
| |

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.
member
Activity: 96
Merit: 36
April 19, 2021, 03:06:06 AM
#5
 Get the private key to this bech32 address
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 19, 2021, 03: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?
member
Activity: 96
Merit: 36
April 19, 2021, 02:17:32 AM
#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     
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 19, 2021, 01: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();
member
Activity: 96
Merit: 36
April 19, 2021, 12:17:12 AM
#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?
Jump to: