Structure

SHA256

An implementation of Secure Hashing Algorithm 2 (SHA-2) hashing with a 256-bit digest.

Declaration

struct SHA256

Overview

The SHA256 hash implements the HashFunction protocol for the specific case of SHA-2 hashing with a 256-bit digest (SHA256Digest). Larger digests take more space, but are more secure.

You can compute the digest by calling the static hash(data:) method once. Alternatively, if the data that you want to hash is too large to fit in memory, you can compute the digest iteratively by creating a new hash instance, calling the update(data:) method repeatedly with blocks of data, and then calling the finalize() method to get the result.

Topics

Specifying the Output Type

typealias SHA256.Digest

The digest type for a SHA256 hash function.

struct SHA256Digest

The output of a Secure Hashing Algorithm 2 (SHA-2) hash with a 256-bit digest.

Reporting the Hash Length

static var byteCount: Int

The number of bytes in a SHA256 digest.

Computing a Hash

static func hash<D>(data: D) -> SHA256Digest

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

Computing a Hash Iteratively

init()

Creates a SHA256 hash function.

func update<D>(data: D)

Incrementally updates the hash function with the given data.

func update(bufferPointer: UnsafeRawBufferPointer)

Incrementally updates the hash function with the contents of the buffer.

func finalize() -> SHA256.Digest

Finalizes the hash function and returns the computed digest.

See Also

Cryptographically Secure Hashes

protocol HashFunction

A type that performs cryptographically secure hashing.

struct SHA512

An implementation of Secure Hashing Algorithm 2 (SHA-2) hashing with a 512-bit digest.

struct SHA384

An implementation of Secure Hashing Algorithm 2 (SHA-2) hashing with a 384-bit digest.