---
title: "exchangeKeys(publicKey:algorithm:parameters:completion:)"
framework: localauthentication
role: symbol
role_heading: Instance Method
path: "localauthentication/laprivatekey/exchangekeys(publickey:algorithm:parameters:completion:)"
---

# exchangeKeys(publicKey:algorithm:parameters:completion:)

Performs a Diffie-Hellman style key exchange operation.

## Declaration

```swift
func exchangeKeys(publicKey: Data, algorithm: SecKeyAlgorithm, parameters: [AnyHashable : Any], completion handler: @escaping @Sendable (Data?, (any Error)?) -> Void)
```

```swift
func exchangeKeys(publicKey: Data, algorithm: SecKeyAlgorithm, parameters: [AnyHashable : Any]) async throws -> Data
```

## Parameters

- `publicKey`: The remote party’s public key.
- `algorithm`: An algorithm suitable for performing this key exchange. For example, ecdhKeyExchangeCofactorX963SHA256.
- `parameters`: A dictionary with parameters for this key exchange.
- `handler`: A completion handler to call when the key exchange operation completes.

## Discussion

Discussion important: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func exchangeKeys(publicKey: Data, algorithm: SecKeyAlgorithm, parameters: [AnyHashable : Any]) async throws -> Data For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously. The algorithm you use determines the parameters in the dictionary that are required or optional. For more information, see SecKeyKeyExchangeParameter.

## See Also

### Performing cryptographic operations

- [decrypt(_:algorithm:completion:)](localauthentication/laprivatekey/decrypt(_:algorithm:completion:).md)
- [sign(_:algorithm:completion:)](localauthentication/laprivatekey/sign(_:algorithm:completion:).md)
