This file contains hidden or 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
import CommonCrypto | |
extension String { | |
var md5: String? { | |
guard let data = self.data(using: .utf8) else { return nil } | |
let hash = data.withUnsafeBytes { (bytes: UnsafePointer<Data>) -> [UInt8] in | |
var hash: [UInt8] = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH)) | |
CC_MD5(bytes, CC_LONG(data.count), &hash) | |
return hash |