<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CryptoKit",
  "identifier" : "/documentation/CryptoKit/HashFunction/hash(data:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple CryptoKit",
      "CryptoKit"
    ],
    "preciseIdentifier" : "s:9CryptoKit12HashFunctionPAAE4hash4data6DigestQzqd___t10Foundation12DataProtocolRd__lFZ"
  },
  "title" : "hash(data:)"
}
-->

# hash(data:)

Computes the digest of the bytes in the given data instance and
returns the computed digest.

```
static func hash<D>(data: D) -> Self.Digest where D : DataProtocol
```

## Parameters

`data`

The data whose digest the hash function should compute. This can
be any type that conforms to
<doc://com.apple.documentation/documentation/Foundation/DataProtocol>,
like <doc://com.apple.documentation/documentation/Foundation/Data> or an
array of <doc://com.apple.documentation/documentation/Swift/UInt8>
instances.

## Return Value

The computed digest of the data.

## Discussion

Use this method if all your data fits into a single data instance. If
the data you want to hash is too large, initialize a hash function and
use the [`update(data:)`](/documentation/CryptoKit/HashFunction/update(data:)) and [`finalize()`](/documentation/CryptoKit/HashFunction/finalize()) methods to compute the
digest in blocks.

---

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)