<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecIdentityCreateWithCertificate(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecIdentityCreateWithCertificate"
  },
  "title" : "SecIdentityCreateWithCertificate(_:_:_:)"
}
-->

# SecIdentityCreateWithCertificate(_:_:_:)

Creates a new identity for a certificate and its associated private key.

```
func SecIdentityCreateWithCertificate(_ keychainOrArray: CFTypeRef?, _ certificateRef: SecCertificate, _ identityRef: UnsafeMutablePointer<SecIdentity?>) -> OSStatus
```

## Parameters

`keychainOrArray`

A reference to a keychain or an array of keychains to search for the associated private key. Specify `NULL` to search the user’s default keychain search list.

`certificateRef`

The certificate for which you want to create an identity.

`identityRef`

On return, an identity object for the certificate and its associated private key. In Objective-C, call the <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> function to release this object when you are finished with it.

## Return Value

A result code. See [Security Framework Result Codes](/documentation/Security/security-framework-result-codes).

## Discussion

If the associated private key is not found in one of the specified keychains, this function fails with an appropriate error code (usually [`errSecItemNotFound`](/documentation/Security/errSecItemNotFound)), and does not return anything in the `identityRef` parameter.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)