我正在尝试在C#中实现ecdsa。我可以从生成密钥 ECKeyPairGenerator,但我需要反向进行。我已经有密钥需要创建一个密钥。
有人可以帮我吗?我用C#编写代码。
public static AsymmetricCipherKeyPair LoadPublicKey(byte[] publickey)
{
string curveName = "prime192v1";
//Here I m generating the key I need to replace but load the public key of byte
var gen = new ECKeyPairGenerator();
X9ECParameters ecP = X962NamedCurves.GetByOid(X9ObjectIdentifiers.Prime192v1);
// var ecP21 = TeleTrusTNamedCurves.GetByName("brainpoolp512t1");
// X9ECParameters ecP = NistNamedCurves.GetByName(curveName);
ECDomainParameters keyGenParam = new ECDomainParameters(ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed());
var secureRandom = new SecureRandom();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(keyGenParam, secureRandom);
gen.Init(genParam);
return gen.GenerateKeyPair();//only want to return public key
}
答案 0 :(得分:1)
您可以尝试
var keyParams = new ECParameters
{
Curve = jwk.Curve.ToECCurve(), #your curve name
Q = new ECPoint #Define X and Y
{
X = jwk.X.FromBase64UrlSafe(),
Y = jwk.Y.FromBase64UrlSafe()
}
};
ECDsa.Create(keyParams);