---
title: "SecTrustCopyPublicKey(_:)"
framework: security
role: symbol
role_heading: Function
path: "security/sectrustcopypublickey(_:)"
---

# SecTrustCopyPublicKey(_:)

Returns the public key for a leaf certificate after it has been evaluated.

## Declaration

```swift
func SecTrustCopyPublicKey(_ trust: SecTrust) -> SecKey?
```

## Parameters

- `trust`: The trust management object for the certificate that has been evaluated. Use the doc://com.apple.security/documentation/Security/SecTrustCreateWithCertificates(_:_:_:) function to create a trust management object.

## Mentioned in

Evaluating a Trust and Parsing the Result Getting an Existing Key

## Return Value

Return Value The leaf certificate’s public key, or NULL if it the public key could not be extracted (this can happen with DSA certificate chains if the parameters in the chain cannot be found). In Objective-C, call the CFRelease function to release this object when you are finished with it.

## Discussion

Discussion Call the SecTrustEvaluateWithError(_:_:) function before calling this function. When you call this function, it attempts to return the public key of the leaf certificate, even if the trust evaluation was unsuccessful. Even if the trust evaluation was successful, this function might still return NULL—for example, if the leaf certificate’s key can’t be extracted for some reason.
