Type Method
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 of exactly 32 bytes. Obtain the lowercase hex form via hexString.
Mentioned In
Discussion
Produces a fixed 32-byte / 256-bit digest per FIPS PUB 180-4 by wrapping the legacy C routines 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.