C#ecdsa签名 - 我可以选择哪个密钥规范? [英] C# ecdsa signature - Which key specification can i choose?
问题描述
我需要在C#端生成ECDSA签名,并在使用(显然)相对公钥读取并验证Android应用程序上的签名。
好吧,要在java中获得ECDSA密钥对(使用充气城堡提供商),代码就像那样
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());
字符串secp224k1
,是曲线名称。我可以选择secp224k1,secp224r1,secp256k1,secp256r1等等。
The string "secp224k1"
, is the curve name. And i can choose "secp224k1","secp224r1","secp256k1","secp256r1" and more others.
我的问题是:
- 上面提到的C#中的等效曲线名称是什么?
- 有人能让我举一个例子,说明如何在C#中,我可以如上面的java代码生成一个keyPair?
提前致谢
推荐答案
我发现了第一个问题:
这是C#中的等效曲线名称上面提到过?
Which is the equivalent curve name in C# mentioned above?
微软库只支持P-256,P-384和P-521NIST推荐的椭圆曲线ID ,这是等效的命名曲线,分别是SEC 2推荐的椭圆曲线域参数的secp256r1,secp384r1,secp521r1,它们相当于prime256v1,但不是ANSI X9.62 ECDSA主曲线ID中的384和521。
C#的Bouncy城堡库支持更多其他曲线,例如我感兴趣的secp224k1。
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.
第二个问题
有人能让我举一个关于如何在C#中生成像上面的java代码一样的keyPair的例子吗?
Could somebody make me an example about how, in C#, i can generate a keyPair like the above java code?
我发现了一个旧例子这里
它说支持的密钥只有3:192位,239位和256位,但我认为是指库的一些旧版本
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
此代码可以演示它
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();
如果有人想要让它变得更好,我认为这个线程可能对所有人都非常宝贵。我只是C#的初学者,这个代码不是我的。 :)
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. :)
这篇关于C#ecdsa签名 - 我可以选择哪个密钥规范?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!