我已经知道使用 BitcoinJ 中的 ECKey 对象从 base58 编码的私钥中获取公钥。请参阅示例代码。
String base58PrivateKeyString = "---------------------private key here---------------------";
NetworkParameters params = MainNetParams.get();
ECKey key;
if (base58PrivateKeyString.length() == 51 || base58PrivateKeyString.length() == 52) {
DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, base58PrivateKeyString);
key = dumpedPrivateKey.getKey();
} else {
BigInteger privKey = Base58.decodeToBigInteger(base58PrivateKeyString);
key = ECKey.fromPrivate(privKey);
}
// I'm not sure that I'm correct. Is this the correct compressed public key?
String publicKey = Hex.toHexString(ECKey.publicKeyFromPrivate(Base58.decodeToBigInteger(base58PrivateKeyString), true));
String bitcoin address; // I don't know how to get
但是我仍然不明白从“密钥”对象中获取压缩的私钥和比特币地址。我尝试了一些compressPoint()方法。但我没有成功。