ecdsa JAVA 私钥推导公钥,有弹性的城堡ECDSA从私钥创建公钥

I am trying to sign a bitcoin transaction in c#. I have 2 bits of code I am trying to complete. I can create a set of private and public keys using Bouncy castle. I can convert this to wallet import format ok.

I can also generate a bitcoin address from the ECDSA public key.

However, I want to sign a transaction and all I have is my private key. I don't want to have to import into a wallet and sign. So how can I generate the public key, given only the private key?

I have found a javascript method that does this:

ecparams.getG().multiply(this.priv).getEncoded();

The only way I've seen in Bouncy Castle is to generate a random pair.

private static AsymmetricCipherKeyPair GenerateKeys(int keySize)

{

ECKeyPairGenerator gen = new ECKeyPairGenerator();

SecureRandom secureRandom = new SecureRandom();

KeyGenerationParameters keyGenParam = new KeyGenerationParameters(secureRandom, keySize);

gen.Init(keyGenParam);

return gen.GenerateKeyPair();

}

解决方案

If you're dealing with DER encoded keys, it's even simpler:

var privateKey = PrivateKeyFactory.CreateKey(bytes) as ECPrivateKeyParameters;

if (privateKey == null)

return null;

Org.BouncyCastle.Math.EC.ECPoint q = privateKey.Parameters.G.Multiply(privateKey.D);

var publicParams = new ECPublicKeyParameters(privateKey.AlgorithmName, q, privateKey.PublicKeyParamSet);

return SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicParams).GetDerEncoded();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值