java – Android:Generating Elliptic Curve KeypPair

I am trying to realize key generation based on Eliptic curves Diffie Hellman. Now I want to specify my Eliptic curve myself, so I use the parameter from here

The code I wrote is to achieve this:

public void createKey(){

        // base point (generator???)
        BigInteger x = new BigInteger("2fe13c0537bbc11acaa07d793de4e6d5e5c94eee8", 16);
        BigInteger y = new BigInteger("289070fb05d38ff58321f2e800536d538ccdaa3d9", 16);

        // the order of generator
        BigInteger n = new BigInteger("5846006549323611672814741753598448348329118574063", 10);

        // curves coefficients
        BigInteger ab = new BigInteger("1", 2);

        // curves cofactor
        BigInteger h = new BigInteger("2", 10);

        // exponents of the equotation
        int[] ks = {7, 6, 3};

        ECFieldF2m ecField = new ECFieldF2m(163, ks);
        // Elliptic curve
        EllipticCurve ec = new EllipticCurve(ecField, ab, ab);

        // GENERATOR POINT
        ECPoint g = new ECPoint(x, y);

        // Parameter specs?
        ECParameterSpec ecps = new ECParameterSpec(ec , g , n, h.intValue());

    try {
        // get keypair
        KeyPairGenerator kg = KeyPairGenerator.getInstance("ECDSA");
        kg.initialize(ecps, new SecureRandom());
        KeyPair kp = kg.generateKeyPair();
        Log.d("SECLIENT"+type,kp.getPublic().toString());
        Log.d("SECLIENT"+type,kp.getPrivate().toString());
    }catch (Exception e){
        e.printStackTrace();
    }
}

At this point, the code compiles. But it is trying_ Failed in catch block, it must generate keypair

The error message is:

Java.lang.runtimeexception: cannot create EC keyfactory: unhandled field class java.security.spec.ecfieldf2m

Does anyone have this question? How can I solve this problem?

resolvent:

I didn't encounter the same problem you encountered, but because you use EC in Android and have a strange runtimeException, I'll leave you 2 cents. I hope it can help you

I have another strange error (OEM related)

java.lang.RuntimeException: error:0f06707b:elliptic curve routines:EC_GROUP_new_by_curve_name:UNKNowN_GROUP

When trying to use

KeyAgreement.getInstance("ECDH);

What happened to me was that I added spongycast as a securityprovider by doing the following:

Security.addProvider(new BouncyCastleProvider());

For some devices, everything works as expected, but for others (i.e. LGE nexus 5), I get exactly the same exception

The way to fix it for me is to change the way I add spongycast and do:

Security.insertProviderAt(new BouncyCastleProvider(), 1);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>