text Sha256Encryptor
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Sha256Encryptor相关的知识,希望对你有一定的参考价值。
struct Encryption {
static func sha256Hex(string: String) -> String? {
guard let messageData = string.data(using: String.Encoding.utf8) else { return nil }
var digestData = Data(count: Int(CC_SHA256_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes {digestBytes in
messageData.withUnsafeBytes {messageBytes in
CC_SHA256(messageBytes, CC_LONG(messageData.count), digestBytes)
}
}
return digestData.map { String(format: "%02hhx", $0) }.joined()
}
static func ccSha256(data: Data) -> Data {
var digest = Data(count: Int(CC_SHA256_DIGEST_LENGTH))
_ = digest.withUnsafeMutableBytes { (digestBytes) in
data.withUnsafeBytes { (stringBytes) in
CC_SHA256(stringBytes, CC_LONG(data.count), digestBytes)
}
}
return digest
}
}
以上是关于text Sha256Encryptor的主要内容,如果未能解决你的问题,请参考以下文章
C# SHA256加密算法记录
关于 BYTE 类型的 strlen() 的警告
hmac sha256和sha256的区别
sha256可以解密吗
sha256WithRSA 签名
SHA256