Objective-C-Bridging-Header.h
#import <CommonCrypto/CommonCrypto.h>
String.swift
extension String {
var MD5: String? {
let length = Int(CC_MD5_DIGEST_LENGTH)
var digest = [UInt8](repeating: 0, count: length)
if let d = self.data(using: .utf8) {
_ = d.withUnsafeBytes { (body: UnsafePointer<UInt8>) in
CC_MD5(body, CC_LONG(d.count), &digest)
}
}
return (0 ..< length).reduce("") {
$0 + String(format: "%02x", digest[$1])
}
}
}