How to create a SecIdentity object using an existing key and certificate?

I am trying to create a SecIdentity object using an existing key and certificate that were stored separately into the keychain in my iOS app. I found the SecIdentityCreateWithCertificate method that seems to do what I need but it looks like it's available only in macOS. Is there an equivalent method for iOS?

I believe you’ll need to use the SecItemAdd function on iOS. Beyond that, you’ll probably want to ask in a more appropriate forum, because your question is about Apple-specific APIs and not about the Swift programming language. For example, I found this Stack Overflow page that might be relevant, and Apple engineer Quinn has posted a number of answers on Apple’s developer forums that might be relevant, like this one.


This is very specific to Apple APIs; if you want to go deeper into it, I recommend that you open a thread on Apple Developer Forums. Tag it with Security so that I see it.

When the system looks for a digital identity, it relies on certain item attributes to line up. See SecItem attributes for keys for the specifics. See the following for a lot more background on the SecItem API:

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple