c# - How to generate EC keypair with Bouncy Castle -
my current project using fips resources of bouncycastle encrypten/decryption signing , on.. keys still generated usual c# bouncy castle. now, because waste want change code, can't find documentation on how this.
what have far:
ecdomainparameters s = new ecdomainparameters(...?) fipsec.keypairgenerator ecgen = cryptoservicesregistrar.creategenerator(new fipsec.keygenerationparameters(s));
but how specify type of curve, g , n?
thanks in advance if can somehow.
i found examples in bouncycastle unit tests. try downloading code tests: https://www.bouncycastle.org/csharp/download/bccrypto-csharp-1.8.1-src.zip or find appropriate source on web page: https://www.bouncycastle.org/csharp/index.html
then class unit test: ectest
for example have code this:
/** * key generation test */ [test] public void testecdsakeygentest() { securerandom random = new securerandom(); biginteger n = new biginteger("883423532389192164791648750360308884807550341691627752275345424702807307"); fpcurve curve = new fpcurve( new biginteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q new biginteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // new biginteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b n, biginteger.one); ecdomainparameters parameters = new ecdomainparameters( curve, curve.decodepoint(hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // g n); eckeypairgenerator pgen = new eckeypairgenerator(); eckeygenerationparameters genparam = new eckeygenerationparameters( parameters, random); pgen.init(genparam); asymmetriccipherkeypair pair = pgen.generatekeypair(); parameterswithrandom param = new parameterswithrandom(pair.private, random); ecdsasigner ecdsa = new ecdsasigner(); ecdsa.init(true, param); byte[] message = new biginteger("968236873715988614170569073515315707566766479517").tobytearray(); biginteger[] sig = ecdsa.generatesignature(message); ecdsa.init(false, pair.public); if (!ecdsa.verifysignature(message, sig[0], sig[1])) { fail("signature fails"); } }
Comments
Post a Comment