Bitcoin Forum
November 18, 2024, 08:27:18 PM *
News: Latest Bitcoin Core release: 28.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 3255 times)
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1080


View Profile
January 05, 2011, 08:28:15 PM
Last edit: January 05, 2011, 09:56:39 PM by grondilu
Merited by ABCbits (2)
 #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.





Hal
VIP
Sr. Member
*
Offline Offline

Activity: 314
Merit: 4276



View Profile
January 05, 2011, 09:39:04 PM
Merited by ABCbits (4)
 #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: 1080


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: 4276



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: 1080


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: 5390
Merit: 13427


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: 1080


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: 4276



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!