in the SWIFT project to build a random objective-c class, you will be prompted to generate a Bridging-header, click Yes, and then delete the Objective-c class just created, leaving only [project name]-bridging-header.h file.
in the [project name]-bridging-header.h file write:
#import <CommonCrypto/CommonDigest.h>
Then write a function that generates MD5:
class func md5string (str:string),string{
var cStr = (strasnsstring). utf8string
var buffer =unsafemutablepointer<UInt8 . Alloc (+)
cc_md5(cStr, (cc_long) (strlen(CSTR)), buffer)
var md5string:nsmutablestring =nsmutablestring( );
for var i = 0; i < ; ++i{
md5string. AppendFormat ("%x2", buffer)
}
free(buffer)
returnString(md5string);
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift development Tutorial--How to encrypt a string MD5