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

# SecCertificateCopyPreferred(_:_:)

Returns the preferred certificate for the specified name and key usage.

```
func SecCertificateCopyPreferred(_ name: CFString, _ keyUsage: CFArray?) -> SecCertificate?
```

## Parameters

`name`

A string containing an email address (RFC 822) or other name for which a preferred certificate is requested.

`keyUsage`

An array containing a list of usage attributes ([`kSecAttrCanEncrypt`](/documentation/Security/kSecAttrCanEncrypt), for example), or `NULL` if you do not want to request a certificate based on a particular usage. See Attribute Item Keys for a complete list of possible usage attributes.

## Return Value

The preferred certificate for the specified name and key usage, or `NULL` if a matching certificate does not exist. In Objective-C, free the certificate with a call to the <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> function when you are done with it.

## Discussion

This function is typically used to obtain the preferred encryption certificate for an email recipient. If a preferred certificate has not been set for the supplied name, this function returns `NULL`. Your code should then perform a search for possible certificates by calling [`SecItemCopyMatching(_:_:)`](/documentation/Security/SecItemCopyMatching(_:_:)).

---

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)