Swift Data MD5

通过bridge文件添加 #import

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)