I am working on a project to implement ECDH on an Android app and My problem is related to Java implementation, it generates a longer public key than I expected.
// 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));
As far as I know or learn from here, if it is a 256-bit curve (secp256k1), keys will be:
Public key: 32 bytes * 2 + 1 = 65 (uncompressed)
Private key: 32 bytes
I expect the output (len of ourPk) 65, but the actual one is 91.