繁体   English   中英

如何将比特币私钥导入 BigInteger?

[英]How to import a bitcoin private key to BigInteger?

我使用以下代码尝试导入比特币私钥并计算公钥。 计算出的 ECPublicKey 不等于 bitcoinPublicKey。 如何纠正?

string bitcoinPrivateKeyStr = "cVnb9S9GgHxsBxfaApvGnWvfwqXRYdV8f1Q2CkQeBa4EsWTNmsGS";
BitcoinSecret bs = new BitcoinSecret(bitcoinPrivateKeyStr);
byte[] bitcoinPrivateKeyBytes = bs.PrivateKey.ToBytes();
byte[] bitcoinPublicKeybytes = bs.PubKey.Decompress().ToBytes();

X9ECParameters curve = SecNamedCurves.GetByName("secp256k1");
ECDomainParameters domain = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);
BigInteger BCPrivateKeyBI = new BigInteger(bitcoinPrivateKeyBytes);
Org.BouncyCastle.Math.EC.ECPoint q = domain.G.Multiply(BCPrivateKeyBI);
ECPrivateKeyParameters ECPrivateKey = new ECPrivateKeyParameters(BCPrivateKeyBI, domain);
ECPublicKeyParameters ECPublicKey = new ECPublicKeyParameters(q, domain);
AsymmetricCipherKeyPair KeyPair = new AsymmetricCipherKeyPair(ECPublicKey, ECPrivateKey);
BigInteger BCPrivateKeyBI = new BigInteger(1, bitcoinPrivateKeyBytes);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM