This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

micro-ecc can't work with android studio

I have to exchange information with smart cellphone. My 10040 board create a pair of key by micro-ecc and transfer the public key to the cellphone. However, the cellphone shows errors like this: the point is not in the curve.

I select the same curve(secp256r1) in 10040 and Android Studio, but it seems the defination of secp256r1 in micro-ecc is no the same as it is in android studion, is that true?

How do I deal with the problem?

Maybe I have to compile micro-ecc to a SO file for android and a dll file for windows, how ever, it's too difficult for me to do such works. Is there anyone knows how to compile micro ecc to the SO and the dll file?

-----More details--2071.3.3-----

I transfer the public key to cellphone in order to do ECDH works, and I failed in converting the row byte array to android ECPublicKey.

public  static String GeneratePublicKey() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    int[] sk_in10040={      0x4E,0xF6,0x1E,0x86,0x79,0x0A,0x36,0x01,0x1F,0x0D,0xFB,0x35,0xE0,0x4C,0x27,0xD0,
                            0xD6,0xCC,0x27,0x8C,0x95,0xEF,0x51,0xF6,0x3A,0xC9,0x60,0xC4,0xBB,0x04,0x34,0x64};
    int[] pk_from10040={    0x81,0x04,0x54,0x6A,0xFD,0xB5,0x0B,0xED,0x7C,0x46,0x72,0x22,0x0F,0x24,0x8E,0xE9,
                            0xF1,0xB1,0xAA,0xC9,0x7D,0xC7,0xD4,0x4C,0x3F,0xAB,0x2B,0xFD,0x8B,0x29,0xBD,0x12,
                            0x1D,0x4D,0xCE,0x82,0x53,0x65,0xB1,0x13,0x1F,0x65,0xB9,0x6D,0x61,0x39,0x40,0x3D,
                            0x14,0x4C,0xDF,0x22,0x80,0xD7,0xF4,0x32,0x61,0x23,0x92,0x0B,0xE2,0xFD,0xAA,0x98};
    byte[] rowbyte = new byte[64];
    for (int i = 0; i <64 ; i++) {
        rowbyte[i] = (byte) pk_from10040[i];
    }
    ECGenParameterSpec ecParamSpec = new ECGenParameterSpec("secp256r1");//select curve
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
    kpg.initialize(ecParamSpec);
    KeyPair kpA = kpg.generateKeyPair();
    ECPublicKey apk= (ECPublicKey) kpA.getPublic();//get a publickey in secp256r1 format
    byte[] android_pk_encode = apk.getEncoded();
    System.arraycopy(rowbyte,0,android_pk_encode,android_pk_encode.length-rowbyte.length,rowbyte.length);
    //keep the head remained while replace the ECPoint data by the row byte array from 10040
    X509EncodedKeySpec ecpks = new X509EncodedKeySpec(android_pk_encode);
    KeyFactory keyFactory = KeyFactory.getInstance("EC");
    ECPublicKey ECDHpk  = null;
    try {
        ECDHpk = (ECPublicKey) keyFactory.generatePublic(ecpks);
    } catch (InvalidKeySpecException e) {
        e.printStackTrace();//failed in generating publickey!!!
    }
    return ECDHpk.toString();//show the information by textview in an activity
}
Related