I'm trying to implement key exchange with HKDF for key derivation. I already looked at Is HKDF implemented in Java Cryptography Architecture? Ask Question , however, I'm still not getting what I am supposed to get.
In python, I have the following (src):
shared = private_key.exchange(ec.ECDH(), peer_public_key).hex()
derived = HKDF(algorithm=hashes.SHA256(), length=32, salt=b'', info=b'', backend=default_backend()).derive(shared.encode()).hex()
This works for python and iOS (I have it implemented there too). However, Android is giving me trouble at the last steps. Can someone elaborate on HKDF for Android?
EDIT: Existing Kotlin code
val keyPairGenerator = KeyPairGenerator.getInstance("EC")
keyPairGenerator.initialize(384)
val keyPair = keyPairGenerator.generateKeyPair()
val peerPublicKey = ... created from external data
val keyAgreement = KeyAgreement.getInstance("ECDH")
keyAgreement.init(keyPair.private)
keyAgreement.doPhase(peerPublicKey, true)
val sharedSecretKey = keyAgreement.generateSecret("ECDH")
Thanks!