Swift版MD5加密

前端之家收集整理的这篇文章主要介绍了Swift版MD5加密前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
extension String  {
var md5: String! {
    let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
    let strLen = CC_LONG(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
    let digestLen = Int(CC_MD5_DIGEST_LENGTH)
    let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
    CC_MD5(str!,strLen,result)
    let hash = NSMutableString()
    for i in 0..<digestLen {
        hash.appendFormat("%02x",result[i])
    }
    result.dealloc(digestLen)
    return String(hash)
}

}

原文链接:https://www.f2er.com/swift/324908.html

猜你在找的Swift相关文章