I am working on a project. Implemented ECDH with C++(Botan library) now I am trying to implement ECDH on Android app and I will try to connect Android to Windows and will check if the shared secret keys are identical. My problem is related to Java implementation, it generates a longer public key than I expected.
As far as I know or learn from here,
If it is a 256-bit curve (secp256k1), keys will be:
Public: 32 bytes * 2 + 1 = 65 (uncompressed) Private: 32 bytes
// Generate ephemeral ECDH keypair
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
kpg.initialize(256);
KeyPair kp = kpg.generateKeyPair();
byte[] ourPk = kp.getPublic().getEncoded();
System.out.println("ourPk len is " + ourPk.length);
// Display our public key
console.printf("Public Key: %s%n", printHexBinary(ourPk));
I expect the output (len of ourPk) 65, but the actual one is 91.