A pure Swift implementation of BLAKE2.
RFC 7693: The BLAKE2 Cryptographic Hash and Message Authentication Code (MAC)
If you don't want to add yet another dependency to your project, you can copy the file
BLAKE2b.swift
(Do not remove the license header!).
You can compute digest in a single step using the static
hash(data:key:digestLength:salt:)
method.
let digest = try BLAKE2b.hash(data: "hello, world!".data(using: .utf8)!)
If you want to compute the digest of a large amount of data, you can initialize
an instance of BLAKE2b
and call update(data:)
as often as you need to.
To finalize and return the digest, call finalize()
.
var hasher = try BLAKE2b()
hasher.update(data: "hello, ".data(using: .utf8)!)
hasher.update(data: "world!".data(using: .utf8)!)
let digest = hasher.finalize()