Swift md5加密
作者:
独孤伊人_xie | 来源:发表于
2018-09-03 12:37 被阅读173次public func md5(strs:String) ->String!{
let str = strs.cString(using: String.Encoding.utf8)
let strLen = CUnsignedInt(strs.lengthOfBytes(using: String.Encoding.utf8))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen)
CC_MD5(str!, strLen, result)
let hash = NSMutableString()
for i in 0 ..< digestLen {
hash.appendFormat("%02x", result[i])
}
result.deinitialize()
return String(format: hash as String)
}
本文标题:Swift md5加密
本文链接:https://www.haomeiwen.com/subject/bfebwftx.html
网友评论