swift3.0 MD5生成

前端之家收集整理的这篇文章主要介绍了swift3.0 MD5生成前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
extension String  {
    var md5: String! {
        let str = self.cString(using: String.Encoding.utf8)
        let strLen = CC_LONG(self.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.deallocate(capacity: digestLen)
        
        return String(format: hash as String)
    }
}
原文链接:https://www.f2er.com/swift/322617.html

猜你在找的Swift相关文章