我是 CryptoKit 的新手,我正在努力将此代码从 Node.js 转换为 Swift(使用 CryptoKit)。
// create a sha256 hmac with the secret
var hmac = crypto.createHmac('sha256', key);
return hmac.update(what).digest('base64');
Run Code Online (Sandbox Code Playgroud)
我在 Swift/CryptoKit 上做的是:
var hmac = SHA256.hash(data: Data(base64Encoded: key)!)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何处理第二行。在 Ruby 上可以这样完成:
HMAC.digest('sha256', secret, what)
Run Code Online (Sandbox Code Playgroud)
但是 CryptoKit“没有”这个方法,有什么想法吗?