---
title: "SecKeyCreateWithData(_:_:_:)"
framework: security
role: symbol
role_heading: Function
path: "security/seckeycreatewithdata(_:_:_:)"
---

# SecKeyCreateWithData(_:_:_:)

Restores a key from an external representation of that key.

## Declaration

```swift
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 doc://com.apple.security/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: doc://com.apple.security/documentation/Security/kSecAttrKeyType doc://com.apple.security/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.

## Mentioned in

Storing Keys as Data

## Return Value

Return Value The restored key or NULL on failure. In Objective-C, call CFRelease to free the key’s memory when you are done with it.
