I'm new to CryptoKit, and I'm struggling to translate this code from Node.js to Swift (using CryptoKit).
// create a sha256 hmac with the secret
var hmac = crypto.createHmac('sha256', key);
return hmac.update(what).digest('base64');
What I'm doing on Swift/CryptoKit is:
var hmac = SHA256.hash(data: Data(base64Encoded: key)!)
but I don't see how to handle the second line. On Ruby it can done on this way:
HMAC.digest('sha256', secret, what)
but CryptoKit "doesn't have" this method, any ideas?
With Swift using CryptoKit you would write this:
The last line computes your "Message Authentication Code".
You can convert this to data:
and as a base64 encoded string:
There are many tutorials from Apple and others in the web.