From the course: iOS Development: Security

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Performing asymmetric encryption

Performing asymmetric encryption - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Performing asymmetric encryption

- [Instructor] The KeychainFacade class can generate the private and the public key pair. These keys are required for asymmetric encryption. Next, we're going to implement the encryption feature. I start by declaring the encrypt method. Let's scroll down. The method has a single parameter of type string. This is our input to be encrypted. The method returns an optional data, and it might throw an error. We need the public key for asymmetric encryption. We can't proceed if there is no public key, so I need to make sure it exists. That's why I use the guard statement, guard let security key equals publicKey, else, we need to throw an error. We'll need a dedicated error for the case when there is no public key. I'm going to define a new error case called noPublicKey. Let's scroll up to the KeychainFacade error, and I'll add the new case, case noPublicKey. Now, let's complete the guard block. Throw KeychainFacadeError.noPublicKey. The next step is about choosing an asymmetric algorithm. I…

Contents