在[工程名]-Bridging-Header.h文件写入:
#import <CommonCrypto/CommonDigest.h>
class func md5String(str:String) ->String{
var cStr = (stras NSString).UTF8String
var buffer =UnsafeMutablePointer<UInt8>.alloc(16)
CC_MD5(cStr,(CC_LONG)(strlen(cStr)),buffer)
var md5String:NSMutableString =NSMutableString();
forvar i = 0; i <16; ++i{
md5String.appendFormat("%X2",buffer)
}
free(buffer)
returnString(md5String);
}
原文链接:https://www.f2er.com/swift/326451.html