Title: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: grondilu on January 05, 2011, 08:28:15 PM *** 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. Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: Hal on January 05, 2011, 09:39:04 PM Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft.
Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: grondilu on January 05, 2011, 09:49:43 PM 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 Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: Hal on January 06, 2011, 12:54:02 AM 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 Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: davux on January 06, 2011, 01:19:24 AM 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.
Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: grondilu on January 06, 2011, 02:09:22 AM 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. Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: theymos on January 06, 2011, 02:26:57 AM 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. Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: grondilu on January 06, 2011, 03:27:39 AM Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft. Would this work with any key for sure ? Title: Re: 50 BTC bounty for a PEM public key to bitcoin address convertor Post by: Hal on January 07, 2011, 12:11:01 AM As long as OpenSSL outputs keys in this format, it will work. I doubt they'd change it due to compatibility.
|