<!--
{
  "documentType" : "article",
  "framework" : "Security",
  "identifier" : "/documentation/Security/creating-an-identity",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Creating an Identity"
}
-->

# Creating an Identity

Create an identity from a certificate and private key.

## Discussion

In macOS, you can create an identity as a combination of a certificate and a private key. You begin by obtaining a certificate reference in one of the ways described in [Getting a Certificate](/documentation/Security/getting-a-certificate). You then supply that reference to the [`SecIdentityCreateWithCertificate(_:_:_:)`](/documentation/Security/SecIdentityCreateWithCertificate(_:_:_:)) function:

```objc
SecCertificateRef certificate = <# a certificate #>;
SecIdentityRef identity = NULL;
OSStatus status =
    SecIdentityCreateWithCertificate(NULL,   // Default keychain search list
                                     certificate,
                                     &identity);
if (status != errSecSuccess) { <# Handle error #> }
else                         { <# Use identity #> }
 
if (identity) { CFRelease(identity); }  // After you are done with it
```

The function attempts to locate the corresponding private key in the default keychain list or in the keychain or keychains that you specify as the first argument. If it succeeds, as indicated by the status result, it populates the identity reference with a pointer to a newly created identity object. Otherwise, the identity reference remains empty.

To persist a copy of the identity for later use, store it in the keychain, as described in [Storing an Identity in the Keychain](/documentation/Security/storing-an-identity-in-the-keychain).

In Objective-C, when you are done with the identity, you are responsible for freeing the object’s memory. In Swift, the system manages the object’s memory automatically, releasing it when the object goes out of scope.

---

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)