C# ecdsa signature - Which key specification can i choose?

只愿长相守 提交于 2019-12-12 08:59:33

问题


i need to generate a ECDSA signature on C# side, and after reading and verify the signature on android application using (obviously) the relative public key. Well, to get a ECDSA key pair in java (with bouncy castle provider), the code is like that

kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
            ecSpec = new ECGenParameterSpec("secp224k1");
kpg.initialize(ecSpec, new SecureRandom());

The string "secp224k1", is the curve name. And i can choose "secp224k1","secp224r1","secp256k1","secp256r1" and more others.

My questions is:

  1. Which is the equivalent curve name in C# mentioned above?
  2. Could somebody make me an example about how, in C#, i can generate a keyPair like the above java code?

Thanks in advance


回答1:


I've found something about my first question:

Which is the equivalent curve name in C# mentioned above?

The microsoft libraries support only P-256, P-384 and P-521 "NIST-recommended elliptic curve ID", that is the equivalent named curve, rispectively, secp256r1, secp384r1, secp521r1 of "SEC 2 recommended elliptic curve domain parameters" that are the equivalent of prime256v1, but not 384 and 521 in ANSI X9.62 ECDSA prime curve ID. Bouncy castle libraries for C#, support more other curves like the secp224k1 that i was interested.

For the second question

Could somebody make me an example about how, in C#, i can generate a keyPair like the above java code?

i've found an old example here It says that the keys supported are only 3: 192 bit, 239 bit and 256 bit, but i think is referred to some old version of the library

this code can demonstrate it

ECKeyPairGenerator gen = new ECKeyPairGenerator("ECDSA");
        SecureRandom secureRandom = new SecureRandom();
        Org.BouncyCastle.Asn1.X9.X9ECParameters ecp = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp224k1");
        ECDomainParameters ecSpec = new ECDomainParameters(ecp.Curve, ecp.G, ecp.N, ecp.H, ecp.GetSeed());
        ECKeyGenerationParameters ecgp = new ECKeyGenerationParameters(ecSpec, secureRandom);
        gen.Init(ecgp);
        AsymmetricCipherKeyPair eckp = gen.GenerateKeyPair();

If somebody wants try to make it better, i think that this thread could be very precious for all. Im only a beginner with C# and this code isn't mine. :)



来源:https://stackoverflow.com/questions/19466907/c-sharp-ecdsa-signature-which-key-specification-can-i-choose

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!