美文网首页
Swift Data MD5

Swift Data MD5

作者: 糊涂糊涂啊 | 来源:发表于2017-10-21 18:09 被阅读127次

通过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
  }
}

相关文章

网友评论

      本文标题:Swift Data MD5

      本文链接:https://www.haomeiwen.com/subject/zgtwuxtx.html