<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "OpenSSL",
  "identifier" : "/documentation/OpenSSL/SHA256/hash(data:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "OpenSSL"
    ],
    "preciseIdentifier" : "s:7OpenSSL6SHA256O4hash4dataAC0C6DigestV10Foundation4DataV_tFZ"
  },
  "title" : "hash(data:)"
}
-->

# hash(data:)

Computes a SHA-256 digest of arbitrary bytes.

```
static func hash(data: Data) -> SHA256.SHA256Digest
```

## Parameters

`data`

The bytes to hash. May be empty; SHA-256 of the
empty string is the well-defined value
`e3b0c442...b855` per FIPS 180-4 §A.1.

## Return Value

A [`SHA256.SHA256Digest`](/documentation/OpenSSL/SHA256/SHA256Digest) of exactly 32 bytes. Obtain the
lowercase hex form via [`hexString`](/documentation/OpenSSL/SHA256/SHA256Digest/hexString).

## Discussion

Produces a fixed 32-byte / 256-bit digest per
[FIPS PUB 180-4](https://csrc.nist.gov/publications/detail/fips/180/4/final)
by wrapping the legacy C routines
[`SHA256_Init`](https://docs.openssl.org/3.6/man3/SHA256_Init/),
`SHA256_Update`, and `SHA256_Final`. Typical uses: integrity
checks over arbitrary payloads, HMAC-SHA256 key derivation, and
content-addressed identifiers (JWT payload fingerprints, Nostr
NIP-01 event IDs, Git-style blob hashes).

Every call allocates a fresh `SHA256_CTX` on the stack, so the
function is safe to call concurrently from multiple tasks without
synchronization. Output is stable across platforms and builds.

> Note: The `SHA256_*` C family is deprecated in OpenSSL 3.0 in
> favor of the `EVP_MD` high-level interface. This wrapper keeps
> the legacy path for simplicity and may migrate to `EVP_MD` in
> a future release — no public API change is expected.