<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecKeyCreateWithData(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecKeyCreateWithData"
  },
  "title" : "SecKeyCreateWithData(_:_:_:)"
}
-->

# SecKeyCreateWithData(_:_:_:)

Restores a key from an external representation of that key.

```
func SecKeyCreateWithData(_ keyData: CFData, _ attributes: CFDictionary, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>?) -> SecKey?
```

## Parameters

`keyData`

Data representing the key. The format of the data depends on the type of key being created. See the description of the return value of the [`SecKeyCopyExternalRepresentation(_:_:)`](/documentation/Security/SecKeyCopyExternalRepresentation(_:_:)) function for details.

`attributes`

A dictionary containing attributes describing the key to be imported. This dictionary must include at least the following keys:

- [`kSecAttrKeyType`](/documentation/Security/kSecAttrKeyType)
- [`kSecAttrKeyClass`](/documentation/Security/kSecAttrKeyClass)

`error`

The address of a <doc://com.apple.documentation/documentation/CoreFoundation/CFError> object. If an error occurs, this is set to point at an error instance that describes the failure.

## Return Value

The restored key or `NULL` on failure. In Objective-C, call <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> to free the key’s memory when you are done with it.

## Discussion

---

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)