Created
August 24, 2016 13:45
-
-
Save jknthn/ba642d4f3d0abf2425a0293c19ca2494 to your computer and use it in GitHub Desktop.
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
var md5: String { | |
let str = self.cString(using: .utf8) | |
let strLen = CUnsignedInt(self.lengthOfBytes(using: .utf8)) | |
let digestLen = Int(CC_MD5_DIGEST_LENGTH) | |
let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen) | |
CC_MD5(str!, strLen, result) | |
let hash = NSMutableString() | |
for i in 0..<digestLen { | |
hash.appendFormat("%02x", result[i]) | |
} | |
result.deinitialize() | |
return String(format: hash as String) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment