【发布时间】:2021-08-31 11:09:25
【问题描述】:
我已经知道使用 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
但我还是不明白要从“key”对象中获取压缩的私钥和比特币地址。我尝试了一些 compressPoint() 方法。但我没有成功。
【问题讨论】: