通过bridge文件添加 #import <CommonCrypto/CommonCrypto.h>
extension Data {
func getMD5String() -> String {
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
_ = withUnsafeBytes { (bytes) in
CC_MD5(bytes, CC_LONG(count), &digest)
}
var digestHex = ""
for index in 0 ..< Int(CC_MD5_DIGEST_LENGTH) {
digestHex += String(format: "%02x", digest[index])
}
return digestHex
}
}
网友评论