I'm trying to perform an EC key exchange between iOS and Android clients of my app. I have successfully transported and generated them from iOS to Android. But I'm unable to use the keys generated in the android app in iOS.
I'm using the SecKeyCreateWithData method in swift to generate keys from 'Data' type, but I'm getting this error:
Error Domain=NSOSStatusErrorDomain Code=-50 "EC public key creation from data failed"
I used the follwing encoding in the android client, it produces a base64 string which I process and pass as Data SecKeyCreateWithData in swift
byte [] encodedPublicKey = PubKey.getEncoded();
String b64PublicKey = Base64.encodeToString(encodedPublicKey,Base64.DEFAULT);
I'd like to generate a SecKeyRef public key, please help
Apple APIs don't follow the standards exactly to play nicely with other platforms. Exporting an EC public key on iOS doesn't include a fixed header identifier. Therefore, the import functions also expect that the header is missing. This means you must remove the header that Android creates when importing the Android EC key.
Here's a portable example:
Swift version: