📜  swift hmac256 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:59.399000             🧑  作者: Mango

代码示例1
import CryptoKit

let secretString = "my-secret"
let key = SymmetricKey(data: secretString.data(using: .utf8)!)

let string = "An apple a day keeps anyone away, if you throw it hard enough"

let signature = HMAC.authenticationCode(for: string.data(using: .utf8)!, using: key)
print(Data(signature).map { String(format: "%02hhx", $0) }.joined()) // 1c161b971ab68e7acdb0b45cca7ae92d574613b77fca4bc7d5c4effab89dab67