سؤال

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

هل كانت مفيدة؟

المحلول

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. :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top