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.

Defining the asymmetric key accessors

Defining the asymmetric key accessors - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Defining the asymmetric key accessors

- [Instructor] Let's complete the asymmetric key generation by exposing the properties required to access the private and the public key. I create a lazy computed property called private key. Let's scroll up. Lazy var private key of type SecKey. So it's a cryptographic key, obviously, and let's implement it. I declared it as lazy to make sure that it only gets initialized once when we refer to the property for the first time. I first look up the private key in the key chain by calling retrieve private key. I use the guard statement and condition of try when calling the method, and if the key is not valid or anything fails. If the private key has been added to the key chain, I call generate private key to create it. As you may recall, generate private key also adds the private key to the key chain. So I simply return the result of calling generate private key as I return the result of calling the retrieve private key. Next, I define the property for the public key. This is also a lazy…

Contents