---
title: "SecIdentityCopyPrivateKey(_:_:)"
framework: security
role: symbol
role_heading: Function
path: "security/secidentitycopyprivatekey(_:_:)"
---

# SecIdentityCopyPrivateKey(_:_:)

Retrieves the private key associated with an identity.

## Declaration

```swift
func SecIdentityCopyPrivateKey(_ identityRef: SecIdentity, _ privateKeyRef: UnsafeMutablePointer<SecKey?>) -> OSStatus
```

## Parameters

- `identityRef`: The identity object for the identity whose private key you wish to retrieve.
- `privateKeyRef`: On return, points to the private key object for the specified identity. The private key must be of class type doc://com.apple.security/documentation/Security/SecItemClass/privateKeyItemClass. In Objective-C, call the doc://com.apple.documentation/documentation/CoreFoundation/CFRelease function to release this object when you are finished with it.

## Mentioned in

Parsing an Identity

## Return Value

Return Value A result code. See Security Framework Result Codes.

## Discussion

Discussion An identity is a digital certificate together with its associated private key.
