<!--
{
  "availability" : [

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

# hash(string:)

Computes a SHA-256 digest of a Swift `String` encoded as UTF-8.

```
static func hash(string: String) -> SHA256.SHA256Digest
```

## Parameters

`string`

The text to hash. UTF-8 encoding is applied
unconditionally; callers needing a different encoding should
call [`hash(data:)`](/documentation/OpenSSL/SHA256/hash(data:)) with explicitly encoded bytes.

## Return Value

A [`SHA256.SHA256Digest`](/documentation/OpenSSL/SHA256/SHA256Digest) of exactly 32 bytes.

## Discussion

A convenience over [`hash(data:)`](/documentation/OpenSSL/SHA256/hash(data:)) that hashes the bytes returned
by `Data(string.utf8)`. Behavior is identical to hashing those
bytes directly; the return type, length, and test-vector
conformance (RFC 6234, FIPS 180-4) are the same.

> Warning: SHA-256 hashes a byte sequence, not a semantic string.
> Two visually identical strings with different Unicode
> normalization forms (NFC vs NFD) produce different digests. When
> the input may come from user-visible text — filenames, labels,
> display names — normalize explicitly (for example with
> `String.precomposedStringWithCanonicalMapping`) before hashing.
> See [UAX No. 15](https://www.unicode.org/reports/tr15/) for the
> normalization forms.