2

I am trying to convert my Bitcoin Address with BitcoinJ in order to look like a normal address such as this: 1J7mdg5rbQyUHENYdx39WVWK7fsLpEoXZy.

I haven't found anything exept for the Base58.encode() which takes the getPubkeyHash() of my ECKey and returns something like this: 5ahorsFsHTcG3f662evowc5c9zf.

Which means that encodes the given bytes in base58,no checksum is appended according to the API.But i want my address to look like the above one.

Is there any algorithm in java for encoding address_byte_string (consisting of 1-byte_version + hash_or_other_data + 4-byte_check_code)?

according to this:https://en.bitcoin.it/wiki/Base58Check_encoding

4

Yes.

ECKey key = ...;
String addr = key.toAddress(MainNetParams.get()).toString();

https://bitcoinj.github.io/javadoc/0.12/org/bitcoinj/core/ECKey.html#toAddress-org.bitcoinj.core.NetworkParameters-

  • thanks for your answer.The key.toAddress() function was the one that i was looking for. – gtopal Jan 2 '16 at 9:23
1

Not Java, but interesting to examine as a reference to explore Java functionality with this fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc being a secp256k1 elliptic curve private key.

  1. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public -u | bx sha256 | bx ripemd160 | bx wrap-encode -v 0 | bx base58-encode 1KNogjhyQ3fSPGpzgAv8gSG5WLVN8L39Ln
  2. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public -u | bx sha256 | bx ripemd160 | bx base58check-encode -v 0 1KNogjhyQ3fSPGpzgAv8gSG5WLVN8L39Ln
  3. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public -u | bx bitcoin160 | bx base58check-encode -v 0 1KNogjhyQ3fSPGpzgAv8gSG5WLVN8L39Ln
  4. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public -u | bx bitcoin160 | bx address-encode -v 0 1KNogjhyQ3fSPGpzgAv8gSG5WLVN8L39Ln
  5. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public | bx bitcoin160 | bx address-encode -v 0 1FbGdbUU1ibBtanPTLAuMTAJ4Y9HkatkcX
  6. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public 02cf90dc2b34937fff7cf1eb4b260f1e5610231134b864761e508505938bbef8fc
  7. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public -u 04cf90dc2b34937fff7cf1eb4b260f1e5610231134b864761e508505938bbef8fc00aeb265797336b74146e018da7b78070f1f1072540a2c3fe83637ca5d605b3c
  8. % echo fc8fba997174132184998ab82b28e441e80c73236ccaf8b6a1efadc33febecfc | bx ec-to-public -u | bx bitcoin160 c991f856a2992c877d3923298e67b88fe61e6c76

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.