---
title: "sign(_:algorithm:completion:)"
framework: localauthentication
role: symbol
role_heading: Instance Method
path: "localauthentication/laprivatekey/sign(_:algorithm:completion:)"
---

# sign(_:algorithm:completion:)

Generates a digital signature for the data you supply.

## Declaration

```swift
func sign(_ data: Data, algorithm: SecKeyAlgorithm, completion handler: @escaping @Sendable (Data?, (any Error)?) -> Void)
```

```swift
func sign(_ data: Data, algorithm: SecKeyAlgorithm) async throws -> Data
```

## Parameters

- `data`: The data to sign. The data is usually the digest of applying a cryptographic hash function to some actual data.
- `algorithm`: An algorithm suitable for this data signing operation. For example, ecdsaSignatureMessageX962SHA256.
- `handler`: A completion handler to call when the signing 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 sign(_ data: Data, algorithm: SecKeyAlgorithm) async throws -> Data For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously.

## See Also

### Performing cryptographic operations

- [decrypt(_:algorithm:completion:)](localauthentication/laprivatekey/decrypt(_:algorithm:completion:).md)
- [exchangeKeys(publicKey:algorithm:parameters:completion:)](localauthentication/laprivatekey/exchangekeys(publickey:algorithm:parameters:completion:).md)
