<!--
{
  "availability" : [
    "iOS: 26.4.0 -",
    "iPadOS: 26.4.0 -",
    "macCatalyst: 26.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WiFiAware",
  "identifier" : "/documentation/WiFiAware/WAConnection/deriveSharedSecret(for:method:context:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Wi-Fi Aware"
    ],
    "preciseIdentifier" : "s:9WiFiAware12WAConnectionC18deriveSharedSecret3for6method7contextAA08WASharedG0VSgAI12ProtocolNameV_AI16DerivationMethodVAI7ContextVtYaF"
  },
  "title" : "deriveSharedSecret(for:method:context:)"
}
-->

# deriveSharedSecret(for:method:context:)

Derive a unique, high-entropy shared secret for this network connection, which can be used to pair and setup security for higher layer network protocols like TLS or IPSec without additional user action or entropy input.

```
func deriveSharedSecret(for protocolName: WASharedSecret.ProtocolName, method: WASharedSecret.DerivationMethod, context: WASharedSecret.Context = .bundleID) async -> WASharedSecret?
```

## Parameters

`protocolName`

The protocol that will be setup, such as TLS, IPSec, or a custom protocol.

`method`

The method to use to derive the shared secret.

`context`

A unique value that is specific to your App and the use case this connection will perform, which diversifies the generated secret. Defaults to the `Bundle ID` of the calling app.

## Return Value

a shared secret unique to the protocol, connection, and context supplied, or `nil` if a secret could not be derived using the provided method.

## Discussion

The shared secret can be used to authenticate a [PAKE](https://en.wikipedia.org/wiki/Password-authenticated_key_agreement) like SPAKE2, which is then used to pair and derive long-term asymmetric keys for authentication and encryption of the upper-layer network protocol.

Both sides of a connection will derive the same shared secret value if the same connection and input parameters are used:

- Your app and a remote app can derive the same shared secret value by calling this function on the same connection, with the same parameters.
- Devices and accessories can derive the same value as your app by using the derivation specified in the Wi-Fi Aware 5.0 standard, and providing the same parameters as used by your app.

Example Usage:

```swift
let secret = await connection.wifiAware?.deriveSharedSecret(for: .tlsPSK, method: .kdfHash256)
```

> Important: If needed, get a new shared secret for each new network connection. Do not save this value, send it to other devices, reuse it across connections, or use it as a long-term authentication or encryption key. Instead, use this to pair higher layer protocols, and derive unique longer-term asymmetric keys for those protocols when pairing them.

---

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)