---
title: "SecKeyCopyPublicKey(_:)"
framework: security
role: symbol
role_heading: Function
path: "security/seckeycopypublickey(_:)"
---

# SecKeyCopyPublicKey(_:)

Gets the public key associated with the given private key.

## Declaration

```swift
func SecKeyCopyPublicKey(_ key: SecKey) -> SecKey?
```

## Parameters

- `key`: The private key for which you want the corresponding public key.

## Mentioned in

Generating New Cryptographic Keys Getting an Existing Key Protecting keys with the Secure Enclave

## Return Value

Return Value The public key corresponding to the given private key. In Objective-C, call the CFRelease function to free this key’s memory when you are done with it.

## Discussion

Discussion The returned public key may be nil if the app that created the private key didn’t also store the corresponding public key in the keychain, or if the system can’t reconstruct the corresponding public key.
