I'm creating an iPhone Objective-C app that uses secure communication between a server and a client. The protocol I want to follow goes like this:
The client is compiled and distributed with the Server's Public RSA key (hardcoded). Let's call this Kspub. (For Key Server Public)
The client generates an random AES key. Let's call this key Kcaes (for Key Client AES)
The client encrypts Kcaes using Kspub, and produces the encrypted text: Kspub(Kcaes)
The client sends Kspub(Kcaes) to the server.
The server decrypts Kspub(Kcaes) using the server's private key, Kspri. This recovers Kcaes. Now the client and the server both share a common AES key, Kcaes.
To verify this, the server encrypts Kcaes USING Kcaes. This produces encrypted text Kcaes(Kcaes).
The server sends Kcaes(Kcaes) to the client.
The client decrypts Kcaes(Kcaes) using the Kcaes key. This produces Kcaes. If this matches the original Kcaes, then the client knows it has established a secure connection.
The client and server can now securely exchange information using symmetrical key Kcaes.
I have already implemented server-side and client-side key generation, encryption, and decryption methods. Currently, keypairs generated on the iPhone are being stored in it's keychain. Here's the issue:
I cannot seem to find a method in Apple's Keychain or Security API to import a Public RSA key from a text file. How can I import a key through a text file and store it in a SecKeyRef object?
Thanks!