简体   繁体   中英

How to import a bitcoin private key to BigInteger?

I use the following codes to try to import a bitcoin private key and compute the public key. The computed ECPublicKey is not equal to bitcoinPublicKey. How to correct?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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