Methods for uncovering the public key of a Bitcoin address

23 replies 278 views
fullnodeSenior Member
Posts: 434 · Reputation: 1205
#1Jul 25, 2023, 10:10 AM
Hey everyone. Just curious if there's a tool or script to get the uncompressed public key from a Bitcoin address. Heard you can find it if the address has sent funds but I'm lost on how to do this. Any help is appreciated. Thanks!
5 Reply Quote Share
0xHashMember
Posts: 431 · Reputation: 210
#2Jul 25, 2023, 10:59 AM
So the deal is that a Bitcoin address is basically a hash of the public key. And since hashing is a one-way street, there’s no way to reverse it. When you send bitcoins, you're signing a message with your private key and this reveals your public key to let others verify you have rights to those coins.
0 Reply Quote Share
cobra51Newbie
Posts: 100 · Reputation: 31
#3Jul 25, 2023, 11:15 AM
I think I asked about this before. Just want to point out that in a P2PKH transaction, the signature script includes the signature followed by the public key. Extract the sigscript, find the signature, and look for OP_Pushbytes_65 (that’s the uncompressed key in hex). You can write a script to get the public key from there.
2 Reply Quote Share
fullnodeSenior Member
Posts: 434 · Reputation: 1205
#4Jul 25, 2023, 11:39 AM
That's interesting but I thought sigscript was the only way to get it.
0 Reply Quote Share
dave.forkMember
Posts: 375 · Reputation: 185
#5Jul 25, 2023, 05:23 PM
Quick note: the full public key is actually 130 characters. Is the lead 65 characters the x-value or what?
0 Reply Quote Share
fullnodeSenior Member
Posts: 434 · Reputation: 1205
#6Jul 25, 2023, 07:52 PM
If an address hasn’t spent any coins, its public key stays hidden. The public key is hashed to create the address. Here’s basically how it works: 1. Generate a 256-bit private key. 2. Use ECDSA for the public key (which is usually compressed). 3. Hash the public key multiple times to get the address.
2 Reply Quote Share
cobra51Newbie
Posts: 100 · Reputation: 31
#7Jul 25, 2023, 11:16 PM
Yeah, I'm talking about addresses that have spent coins, so the public key is out there.
0 Reply Quote Share
fullnodeSenior Member
Posts: 434 · Reputation: 1205
#8Jul 26, 2023, 02:46 AM
Checking this address: 1MsHWS1BnwMc3tLE8G35UXsS58fKipzB7a Here’s the TXID: 3410bc9f7671d30225678a870f8d695cad1af6f64b0a319a487d3b86540794ab The ScriptSig looks like this: 48 gives you the signature, and then you get the 41 for the public key. Pretty straight-up.
2 Reply Quote Share
hash_lordNewbie
Posts: 18 · Reputation: 2
#9Jul 26, 2023, 05:09 AM
So the public key is the last 130 characters, right?
1 Reply Quote Share
kevin2020Senior Member
Posts: 69 · Reputation: 1249
#10Jul 26, 2023, 05:28 AM
I'm trying to figure out how to reverse it get the address from an uncompressed public key. Any tips on how to make sure the public key I’m gathering is right?
6 Reply Quote Share
fullnodeSenior Member
Posts: 434 · Reputation: 1205
#11Jul 26, 2023, 09:26 AM
You can use a tool for that. Just ignore the private key box and put your public key in the right spot. It'll walk you through the steps and spit out the address.
3 Reply Quote Share
cobra51Newbie
Posts: 100 · Reputation: 31
#12Jul 26, 2023, 10:41 AM
A full public key equals 130 hexadecimal characters, while a compressed one is 66 hexadecimal characters. The coords don’t just pop out, you have to derive them based on whether y is even or odd.
4 Reply Quote Share
mr_apeNewbie
Posts: 401 · Reputation: 35
#13Jul 26, 2023, 03:20 PM
This is helpful but I’m struggling. When I pull the last 130 hex from a transaction and use these tools, it often doesn't relate to the address or is an invalid key.
0 Reply Quote Share
hash_lordNewbie
Posts: 18 · Reputation: 2
#14Jul 26, 2023, 08:43 PM
Are you sure it's uncompressed? Most keys are compressed nowadays, so look for 66 characters. Could you show a transaction example?
1 Reply Quote Share
proto2019Newbie
Posts: 3 · Reputation: 15
#15Jul 26, 2023, 09:45 PM
Just saying... if you're jumping into random transactions, you’ll keep getting confused. Start by learning transaction structures and Bitcoin scripts first.
0 Reply Quote Share
pixel_stakeSenior Member
Posts: 23 · Reputation: 1132
#16Jul 27, 2023, 12:11 AM
Let’s look at this recent transaction: Check the sigscript: the last 130 chars didn’t start with '04', so it’s not uncompressed. Surprising, considering how recent it is. Then we check the last 66 chars which started with '02', indicating it’s likely compressed.
1 Reply Quote Share
mr_apeNewbie
Posts: 401 · Reputation: 35
#17Jul 27, 2023, 03:21 AM
Thanks for clarifying. If I have a transaction where I see no output, how do I get the public key if I only have a HASH160?
0 Reply Quote Share
proto2019Newbie
Posts: 3 · Reputation: 15
#18Jul 27, 2023, 08:18 AM
Be careful! You can only derive a public key if an address has output transactions. If it hasn't sent BTC, you’re outta luck.
0 Reply Quote Share
pixel_stakeSenior Member
Posts: 23 · Reputation: 1132
#19Jul 27, 2023, 09:44 AM
Hash algorithms aren't reversible, so you can't nail down the public key from a hash directly.
4 Reply Quote Share
proto2019Newbie
Posts: 3 · Reputation: 15
#20Jul 28, 2023, 03:48 PM
Alright.
2 Reply Quote Share

Related topics