Title: I have WIF private key and try convert to HEX private key (JAVA) Post by: Sanka555 on December 18, 2021, 07:50:05 PM I need to do like in this calculator https://secretscan.org/PrivateKeyWif
the entrance is invited 5KWDpqqbx24hZmqMzHUAsVZVEJiJukK4MP25ZuyDMapAVs4s6p3 at the output I get DE5FBB6104D65246E31486BF004701E8A9FA0C388BFA0D6CB8E6F1C1A117CB90 how to do it on JAva? i tried to convert wif to hex both as string and as byte array. the correct answer is not obtained. I would be very grateful for any ideas Title: Re: I have WIF private key and try convert to HEX private key (JAVA) Post by: NeuroticFish on December 18, 2021, 08:04:27 PM You should start with https://en.bitcoin.it/wiki/Wallet_import_format
From want I understand you want to do the second part (https://en.bitcoin.it/wiki/Wallet_import_format#WIF_to_private_key). For base58 decoder, take a look if this works: https://gist.github.com/vrotaru/1753908 I'd add that it may be nice if you do then the steps from the first part (https://en.bitcoin.it/wiki/Wallet_import_format#Private_key_to_WIF)and verify the checksum for the sake of your users. Title: Re: I have WIF private key and try convert to HEX private key (JAVA) Post by: BlackHatCoiner on December 18, 2021, 08:05:45 PM Disclaimer: I want you to understand the technical part. I could just give you few lines of code that do the work, but I insist on acknowledging this procedure.
A WIF private key is a base58 encoding of four things;
For instance, let's say that I want to convert to WIF the following number: Code: b483cd7d8a5245e6d7c4fc4b06de669a15ce3256b7c4d0a08a5a0ab75a0db46d Step 1: Code: 80 Step 2: Code: 80b483cd7d8a5245e6d7c4fc4b06de669a15ce3256b7c4d0a08a5a0ab75a0db46d Step 3: (Compressed public key) Code: 80b483cd7d8a5245e6d7c4fc4b06de669a15ce3256b7c4d0a08a5a0ab75a0db46d01 (Double hash of the above is 01c46123132816f6f7158ddb53fad901bcc9896b84d1b960c26f8dd62e42039a) Thus, step 4: Code: 80b483cd7d8a5245e6d7c4fc4b06de669a15ce3256b7c4d0a08a5a0ab75a0db46d0101c46123 By converting it to base58 you get: Code: L3GcE8o5kgmRhJF1gavfUMjHsz2tSgZYseQeQbD1iTkHBvQoR7A2 To achieve what you want, just go backwards. Code: 5KWDpqqbx24hZmqMzHUAsVZVEJiJukK4MP25ZuyDMapAVs4s6p3 Decode the base58: Code: 80DE5FBB6104D65246E31486BF004701E8A9FA0C388BFA0D6CB8E6F1C1A117CB9006F6CF1C Remove the last 8 characters: Code: 80DE5FBB6104D65246E31486BF004701E8A9FA0C388BFA0D6CB8E6F1C1A117CB90 I can recognize it's an uncompressed address. Therefore, you don't remove the last 2 characters. Just remove the prefix at the start and you have your number: Code: DE5FBB6104D65246E31486BF004701E8A9FA0C388BFA0D6CB8E6F1C1A117CB90 Title: Re: I have WIF private key and try convert to HEX private key (JAVA) Post by: PawGo on December 18, 2021, 08:46:25 PM Of course my dear Sanka555, this is the solution:
Code: String toCheck = "5KWDpqqbx24hZmqMzHUAsVZVEJiJukK4MP25ZuyDMapAVs4s6p3"; I hope your project is progressing well ;-) I have told you already 5 times - check sourcecode of my https://github.com/PawelGorny/WifSolver (https://github.com/PawelGorny/WifSolver), you will find answers for all (ok, most of) your questions. Title: Re: I have WIF private key and try convert to HEX private key (JAVA) Post by: Sanka555 on December 19, 2021, 06:56:32 AM Many thanks to everyone. It's a pity I saw the last answer late)))
Here's what I wrote. It works ;D Quote public static String wifToHex(String wifKey) throws Exception { byte[] bytes = Base58.decode(wifKey); String pk = bytesToHex(bytes); pk = pk.substring(2, pk.length() - 8); return pk; } public static String bytesToHex(byte[] in) { final StringBuilder builder = new StringBuilder(); for (byte b : in) { builder.append(String.format("%02x", b)); } return builder.toString(); } Title: Re: I have WIF private key and try convert to HEX private key (JAVA) Post by: pooya87 on December 19, 2021, 07:30:49 AM Code: public static String wifToHex(String wifKey) throws Exception { Title: Re: I have WIF private key and try convert to HEX private key (JAVA) Post by: MixMAx123 on December 19, 2021, 06:44:09 PM In Java:
Code: public static String Base58ToHexString(String str, int laenge) |