Bitcoin Forum
May 09, 2024, 10:41:50 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: 50 BTC bounty for a PEM public key to bitcoin address convertor  (Read 3222 times)
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
January 05, 2011, 08:28:15 PM
Last edit: January 05, 2011, 09:56:39 PM by grondilu
 #1

*** EDIT:  bounty has closed.  Hal won it. ***

I've tried to make one but I've failed, so I start an other bounty.

dirtyfilthy has made a C program which exports a wallet's private key to a openssl readable PEM format.


So given a bitcoin address such as :

btc=1Hy9dexzNzjvQYkYy6zKRVZMU8k2j5vuPt


I can run :

bc_key $btc ~/.bitcoin/wallet.dat |
openssl ec -pubout

Which gives me a public key :

-----BEGIN PUBLIC KEY-----
MIH1MIGuBgcqhkjOPQIBMIGiAgEBMCwGByqGSM49AQECIQD/////////////////
///////////////////+///8LzAGBAEABAEHBEEEeb5mfvncu6xVoGKVzocLBwKb
/NstzijZWfKBWxb4F5hIOtp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuAIh
AP////////////////////66rtzmr0igO7/SXozQNkFBAgEBA0IABJJ6TBhmiWm4
Y1ACBVJVn0oyG9Ay5IzEZq8cPyrs1PERl963YQh5UrGOT0NodynfHswkz8bUpaJW
FsowR/l9wXc=
-----END PUBLIC KEY-----


Now I need a program that reads this public key, and ouputs the corresponding bitcoin address.

Such a program exists in the bitcoin code.  I think it's the function "PubKeyToAddress" in base58.h.

I want to implement this function in bash, using only openssl et standard filters.

As I understand it, I have to do the following steps :

- computes the sha256 of the key ;
- computes the rmd160 of this hash ;
- add a byte at the begin for the version number (?) ;
- add four bytes at the end for the check sum ;
- encode the result in base58 ;




I've tried using blockexplorer.com/q/hashtoaddress for the last three steps.  This gave me this code :


wget -O - -q http://blockexplorer.com/q/hashtoaddress/$(
grep -v 'PUBLIC KEY' <<<"
-----BEGIN PUBLIC KEY-----
MIH1MIGuBgcqhkjOPQIBMIGiAgEBMCwGByqGSM49AQECIQD/////////////////
///////////////////+///8LzAGBAEABAEHBEEEeb5mfvncu6xVoGKVzocLBwKb
/NstzijZWfKBWxb4F5hIOtp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuAIh
AP////////////////////66rtzmr0igO7/SXozQNkFBAgEBA0IABJJ6TBhmiWm4
Y1ACBVJVn0oyG9Ay5IzEZq8cPyrs1PERl963YQh5UrGOT0NodynfHswkz8bUpaJW
FsowR/l9wXc=
-----END PUBLIC KEY-----" |
base64 -d |
openssl dgst -sha256 |
cut -d\  -f2 |
xxd -r -p |
openssl dgst -rmd160 |
cut -d\  -f2
)


But it just doesn't give me the correct bitcoin address.

50 BTC for whoever fixes that.





1715294510
Hero Member
*
Offline Offline

Posts: 1715294510

View Profile Personal Message (Offline)

Ignore
1715294510
Reply with quote  #2

1715294510
Report to moderator
1715294510
Hero Member
*
Offline Offline

Posts: 1715294510

View Profile Personal Message (Offline)

Ignore
1715294510
Reply with quote  #2

1715294510
Report to moderator
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715294510
Hero Member
*
Offline Offline

Posts: 1715294510

View Profile Personal Message (Offline)

Ignore
1715294510
Reply with quote  #2

1715294510
Report to moderator
1715294510
Hero Member
*
Offline Offline

Posts: 1715294510

View Profile Personal Message (Offline)

Ignore
1715294510
Reply with quote  #2

1715294510
Report to moderator
1715294510
Hero Member
*
Offline Offline

Posts: 1715294510

View Profile Personal Message (Offline)

Ignore
1715294510
Reply with quote  #2

1715294510
Report to moderator
Hal
VIP
Sr. Member
*
Offline Offline

Activity: 314
Merit: 3853



View Profile
January 05, 2011, 09:39:04 PM
 #2

Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft.

Hal Finney
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
January 05, 2011, 09:49:43 PM
 #3

Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft.

Thank you !  You want the 50 BTC ?

PS oh sorry I hadn't seen you bitcoin address in your signature.


Paiement done
23a76591017b364bc3e9ee4a8cf0a317d1a1dfa571190b5caf91c1b9a647747e

Hal
VIP
Sr. Member
*
Offline Offline

Activity: 314
Merit: 3853



View Profile
January 06, 2011, 12:54:02 AM
 #4

That's very generous, but I don't feel right taking the bounty for 5 minute's work. I'll send back the 50. Is that address in the top post yours?

btc=1Hy9dexzNzjvQYkYy6zKRVZMU8k2j5vuPt

Hal Finney
davux
Sr. Member
****
Offline Offline

Activity: 288
Merit: 263


Firstbits.com/1davux


View Profile WWW
January 06, 2011, 01:19:24 AM
 #5

I'm still a new bee, but http://blockexplorer.com/tx/23a76591017b364bc3e9ee4a8cf0a317d1a1dfa571190b5caf91c1b9a647747e seems to indicate that it would work to send the coins to 13p65vr9qsJX5iHv3vW5s6iXJejiBoTibx.

1DavuxH9tLqU4c7zvG387aTG4mA7BcRpp2
México (Oaxaca) – France - Leeds
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
January 06, 2011, 02:09:22 AM
Last edit: January 06, 2011, 02:27:52 AM by grondilu
 #6

That's very generous, but I don't feel right taking the bounty for 5 minute's work. I'll send back the 50. Is that address in the top post yours?

btc=1Hy9dexzNzjvQYkYy6zKRVZMU8k2j5vuPt

Yes it is.  Thanks.

theymos
Administrator
Legendary
*
Offline Offline

Activity: 5194
Merit: 12982


View Profile
January 06, 2011, 02:26:57 AM
 #7

I'm still a new bee, but http://blockexplorer.com/tx/23a76591017b364bc3e9ee4a8cf0a317d1a1dfa571190b5caf91c1b9a647747e seems to indicate that it would work to send the coins to 13p65vr9qsJX5iHv3vW5s6iXJejiBoTibx.

It's not safe to do this. The "from" address could be some random MyBitcoin address.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
January 06, 2011, 03:27:39 AM
 #8

Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft.

Would this work with any key for sure ?

Hal
VIP
Sr. Member
*
Offline Offline

Activity: 314
Merit: 3853



View Profile
January 07, 2011, 12:11:01 AM
 #9

As long as OpenSSL outputs keys in this format, it will work. I doubt they'd change it due to compatibility.

Hal Finney
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!