Many times we will use md5 encryption, here is swift 3.0 the implementation method:
The first new bridge file xx-Bridging-Header , the method is many, here is not introduced.
Then introduce the encryption library in the bridging file
#import <CommonCrypto/CommonDigest.h>
Create a new Swift extension class file String+extension
extension String {///MD5 Encryption/// ///-returns:32 Bit capitalFunc ss_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 () forIinch 0.. <Digestlen {Hash.appendformat ("%02x", Result[i])} Result.deinitialize ()returnString (Format:hash asString)}}
How to use:
Let Md5str = Str.ss_md5 ()
Swift MD5 Encryption