Swift 3 making sha1, sha256 and md5 functions

前端 未结 4 2332
清歌不尽
清歌不尽 2021-02-20 07:05

In Swift 2, I used the following code to extend string variables and to be able to make sha1, sha256, and md5.

After moving to swift 3, the code is not working any more!

4条回答
  •  渐次进展
    2021-02-20 07:41

    func MD5() -> String {
    
        let length = Int(CC_MD5_DIGEST_LENGTH)
        var digest = [UInt8](repeating: 0, count: length)
        if let d = self.data(using: String.Encoding.utf8) {
            d.withUnsafeBytes { (body: UnsafePointer) in
                CC_MD5(body, CC_LONG(d.count), &digest)
            }
        }
        return (0..

提交回复
热议问题