Last active
August 10, 2018 09:36
-
-
Save t089/3d3e703d0c54f0751828f9432bbdfb0b to your computer and use it in GitHub Desktop.
CommonCrypto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array where Element == UInt8 { | |
var md5Hash: [UInt8] { | |
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH)) | |
CC_MD5(self, UInt32(self.count), &hash) | |
return hash | |
} | |
var hexString : String { | |
return self.reduce(into: "", { $0 += String(format: "%02x", $1) }) | |
} | |
} | |
let bytes = Array("Test".utf8) | |
let md5 = bytes.md5Hash.hexString | |
md5 == "0cbc6611f5540bd0809a388dc95a615b" // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment