Use md5 in swift and md5 in swift
Use md5by Wu xueying in swift
Add # import <CommonCrypto/CommonCrypto. h> extension String {var MD5: String {
Let cString = self. cStringUsingEncoding (NSUTF8StringEncoding)
Let length = CUnsignedInt (
Self. lengthOfBytesUsingEncoding (NSUTF8StringEncoding)
)
Let result = UnsafeMutablePointer <CUnsignedChar>. alloc (Int (CC_MD5_DIGEST_LENGTH ))
CC_MD5 (cString !, Length, result)
ReturnString (format: "% 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x ",
Result [0], result [1], result [2], result [3], result [4], result [5], result [6], result [7], result [8],
Result [9], result [10], result [11], result [12], result [13], result [14], result [15])
}}
Usage:
Println ("rain". MD5)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.