Author

Topic: 50 BTC bounty for a PEM public key to bitcoin address convertor (Read 3248 times)

Hal
vip
Activity: 314
Merit: 4041
As long as OpenSSL outputs keys in this format, it will work. I doubt they'd change it due to compatibility.
legendary
Activity: 1288
Merit: 1080
Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft.

Would this work with any key for sure ?
administrator
Activity: 5222
Merit: 13032
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.
legendary
Activity: 1288
Merit: 1080
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.
sr. member
Activity: 288
Merit: 263
Firstbits.com/1davux
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.
Hal
vip
Activity: 314
Merit: 4041
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
legendary
Activity: 1288
Merit: 1080
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
Activity: 314
Merit: 4041
Try doing tail -c 65 after the base64 -d. Your pubkey has ASN.1 cruft.
legendary
Activity: 1288
Merit: 1080
*** 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.




Jump to: