I have generated key pair using Secure Enclave (EC, 256). I have shared my public key(Pub1) with server using SecKeyCopyExternalRepresentation.
Now, I want the server to encrypt some data (data1) using this shared public key so I can decrypt the data(data1) and use it in my business.
Some context of Server side ECC:
Server will also have its EC key pair (Pub2/Pk2). Server will use its Private Key (Pk2) and the received Public Key from iOS application(Pub1) to generate a shared secret (KeyAgreement). Server can then encrypt the data (data1) using this shared secret and using the Symmetric Key algorithm (e.g. AES-GCM) and send to iOS application along with server public key (Pub2).
Server ECC capabilities support ECDH KeyAgreement only and not the pure asymmetric encryption similar to RSA.
The challenge on iOS as per the documentation of eciesEncryptionCofactorX963SHA256AESGCM is that we do not find a way to pass the server public key and decrypt using SecKeyCreateDecryptedData API.
As per API doc as below -
@constant kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM
Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM in new code.
Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256. AES Key size
is 128bit for EC keys <=256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF,
and static public key data is used as authenticationData for AES-GCM processing. AES-GCM uses 16 bytes long TAG and
all-zero 16 byte long IV (initialization vector).
We are struggling to find out the ways
1) How can we use server public key(Pub2) to decrypt data (data1) with above mentioned API ?
2) IF #1 above is not possible, what static Public key (as it is mentioned in API doc) can be used at server side?
3) as the algorithm on iOS mentioned SHA256AESGCM, we understand that some shared secret is derived internally by iOS which is then used for AES-GCM crypto. Please guide us through this internal algorithm.
Please help us how can server and iOS application support this type of encryption decryption ?