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 decryption

Performing asymmetric decryption - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Performing asymmetric decryption

- [Narrator] The KeychainFacade class can generate the asymmetric key pair and it can also encrypt the string. Now, let's add the decrypt feature, too. I declare a new method called decrypt. It takes the encrypted data as input. The method returns the decrypted data, or nil if something goes wrong. So let's return an optional Data. The method may also throw an error, so let's mark it as such. Let me scroll up a bit, alright. Next, we'll check if we have a private key. We need the private key for asymmetric decryption. Guard let secKey equals privateKey. If there is no privateKey, we should throw a dedicated error, KeychainFacadeError, and we need a new case when there is no privateKey defined. So let's scroll back, and I'm going to add a case noPrivateKey. Next, I check if the hardware supports the given algorithm. It's the same logic we used in the encrypt method, so I can copy and paste those lines of code, and let's paste it here. To decrypt the data, we'll rely on the secKey…

Contents