<!--
{
  "availability" : [
    "macOS: 10.7.0 - 12.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecKeyCreateFromData(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecKeyCreateFromData"
  },
  "title" : "SecKeyCreateFromData(_:_:_:)"
}
-->

# SecKeyCreateFromData(_:_:_:)

Constructs a SecKeyRef object for a symmetric key.

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

## Parameters

`parameters`

A parameter dictionary that describes the key. See the discussion for details.

`keyData`

A `CFDataRef` object that contains the raw key data.

`error`

A pointer to a <doc://com.apple.documentation/documentation/CoreFoundation/CFError> variable where an error object is stored upon failure. If not `NULL`, the caller is responsible for checking this variable and releasing the resulting object if it exists.

## Return Value

A symmetric key. In Objective-C, call the <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> function to free the key’s memory when you are done with it.

## Discussion

The parameters dictionary must contain (at minimum) an entry for the [`kSecAttrKeyType`](/documentation/Security/kSecAttrKeyType) key with a value of [`kSecAttrKeyTypeAES`](/documentation/Security/kSecAttrKeyTypeAES) or any other key type defined in Key Type Value.

The keys below may be optionally set in the parameters dictionary (with a `CFBooleanRef` value) to override the default key usage values:

- [`kSecAttrCanEncrypt`](/documentation/Security/kSecAttrCanEncrypt)
- [`kSecAttrCanDecrypt`](/documentation/Security/kSecAttrCanDecrypt)
- [`kSecAttrCanWrap`](/documentation/Security/kSecAttrCanWrap)
- [`kSecAttrCanUnwrap`](/documentation/Security/kSecAttrCanUnwrap)

These values default to `true` if no value is specified.

---

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)