func sha256(data : Data) -> Data {
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash)
}
return Data(hash)
}
@IBAction func touch(_ sender: Any) {
let data = "123456".data(using: String.Encoding.utf8)
print(sha256(data: data!).base64EncodedString())
}
网友评论