我已阅读 How do I obtain the public key from an ECDSA private key in OpenSSL?
并且想要做同样的事情,但是在 Java 中使用 Bouncy CaSTLe。
我也见过Bouncy Castle ESCDA Create Public Key from Private Key但这并没有帮助。
最佳答案
看一下下面的代码,它是c#的,但在java中它是类似的。在此示例中,私钥由 Base64 编码字符串给出,并且还返回一个 Base64 编码字符串。注释的 keyParameters 有效,因此如果您想要关键点和曲线,请使用此参数。
private static readonly Org.BouncyCastle.Asn1.X9.X9ECParameters curve = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256r1");
private static readonly Org.BouncyCastle.Crypto.Parameters.ECDomainParameters domain = new Org.BouncyCastle.Crypto.Parameters.ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);
public string GetPublicKey(string privKey)
{
Org.BouncyCastle.Math.BigInteger d = new Org.BouncyCastle.Math.BigInteger(Convert.FromBase64String(privKey));
//var privKeyParameters = new Org.BouncyCastle.Crypto.Parameters.ECPrivateKeyParameters(d, domain);
Org.BouncyCastle.Math.EC.ECPoint q = domain.G.Multiply(d);
//var pubKeyParameters = new Org.BouncyCastle.Crypto.Parameters.ECPublicKeyParameters(q, domain);
return Convert.ToBase64String(q.GetEncoded());
}
关于java - 如何使用 Bouncy CaSTLe 从 Java 中的 ECDSA 私钥获取公钥?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33525489/