Created
December 14, 2016 13:19
-
-
Save bleft/364d64b36974097f6f8f62001676e108 to your computer and use it in GitHub Desktop.
get md5 hash from Data in swift
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 Data { | |
var md5 : String { | |
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH)) | |
_ = self.withUnsafeBytes { bytes in | |
CC_MD5(bytes, CC_LONG(self.count), &digest) | |
} | |
var digestHex = "" | |
for index in 0..<Int(CC_MD5_DIGEST_LENGTH) { | |
digestHex += String(format: "%02x", digest[index]) | |
} | |
return digestHex | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment