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

# SecCertificateSetPreference

Sets the preferred certificate for a specified name, key use, and date.

```
OSStatus SecCertificateSetPreference(SecCertificateRef certificate, CFStringRef name, uint32 keyUsage, CFDateRef date);
```

## Parameters

`certificate`

The certificate object identifying the preferred certificate.

`name`

A string containing an email address (RFC822) or other name with which the preferred certificate is to be associated.

`keyUsage`

A key use value, as defined in `Security.framework/cssmtype.h`. Pass `0` if you don’t want to specify a particular key use.

`date`

The date after which this preference is no longer valid. If supplied, the preferred certificate is changed only if this date is later than the currently saved setting. Pass `NULL` if this preference should not be restricted by date.

## Return Value

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

## Discussion

This function is typically used to set the preferred encryption certificate for an email recipient, either manually (when encrypting email to a recipient) or automatically upon receipt of encrypted email.

### Special Considerations

Use [`SecCertificateSetPreferred(_:_:_:)`](/documentation/Security/SecCertificateSetPreferred(_:_:_:)) for new development instead.

Because this preference is stored in the default keychain, if the keychain is locked, the system asks the user for a password or other token to unlock it. This function can therefore block while waiting for user input.

---

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)