在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
import Foundation extension Int { func hexedString() -> String { return NSString(format:"%02x", self) as String } } extension NSData { func hexedString() -> String { var string = String() let unsafePointer = bytes.assumingMemoryBound(to: UInt8.self) for i in UnsafeBufferPointer<UInt8>(start:unsafePointer, count: length) { string += Int(i).hexedString() } return string } func MD5() -> NSData { let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH))! let unsafePointer = result.mutableBytes.assumingMemoryBound(to: UInt8.self) CC_MD5(bytes, CC_LONG(length), UnsafeMutablePointer<UInt8>(unsafePointer)) return NSData(data: result as Data) } } extension String { func MD5() -> String { let data = (self as NSString).data(using: String.Encoding.utf8.rawValue)! as NSData return data.MD5().hexedString() } }
转载请注明出处:http://www.cnblogs.com/ficow/p/7132289.html |
请发表评论