A type that performs cryptographically secure hashing.
The ``HashFunction`` protocol describes an interface for computing a
fixed-length digest from an arbitrarily large collection of bytes. Because
the digest is small, you can quickly compare the digests to detect a
difference in two corresponding data sets. Alternatively, transmit or store
data with its digest to detect changes introduced after initially
calculating the digest.
Use one of the protocol’s adopters, like ``SHA256``, ``SHA384``, or
``SHA512``, to output a digest whose value varies significantly over even
small differences in the input data.
Checking a digest doesn’t guard against changes made by a malicious user who
also changes the digest to match. To handle this, compute a message
authentication code (MAC) like ``HMAC`` instead. MACs rely on hashing, but
incorporate a secret cryptographic key into the digest computation. Only a
user that has the key can generate a valid MAC.
Members (1)
method · iOS 13.0+
update
Swift declaration
mutating func update<D>(data: D) where D : DataProtocol
Incrementally updates the hash function with the given data.
Call this method one or more times to provide data to the hash function
in blocks. After providing the last block of data, call the
``finalize()`` method to get the computed digest. Don’t call the update
method again after finalizing the hash function.
- Parameters:
- data: The next block of data for the ongoing digest calculation. You
can provide this as 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.
Skipped declarations
3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
HashFunction.update(bytes:)
The iOS SDK compiler rejected this binding: instance method 'arg' requires that 'RawSpan' conform to 'Escapable'
HashFunction.hash(bytes:)
Static protocol requirements cannot be called through an instance.
HashFunction.hash(data:)
Static protocol requirements cannot be called through an instance.