import CryptoKit
/*:
加密,使用HMAC密钥
*/
let key = SymmetricKey(size: .bits256)
let theme = "asdfasfsdä343433dfdfgdfsdf"
let data = theme.data(using: .utf8)!
let encryptedContent = try! ChaChaPoly.seal(data, using: key).combined
print(encryptedContent)
/*:
解密
*/
let sealedBox = try! ChaChaPoly.SealedBox(combined: encryptedContent)
let decryptedTheme = try! ChaChaPoly.open(sealedBox, using: key)
var str = String(data:decryptedTheme, encoding:.utf8)文章来源:https://www.toymoban.com/news/detail-435746.html
print(str!)文章来源地址https://www.toymoban.com/news/detail-435746.html
到了这里,关于SWIFT HMAC加密、解密的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!