//需引用头文件
#import <CommonCrypto/CommonCrypto.h>
//sha1
func sha1() -> String{
let data = self.data(using: String.Encoding.utf8, allowLossyConversion: true)!
let uint8Ptr = UnsafeMutablePointer<UInt8>.allocate(capacity: data.count)
uint8Ptr.initialize(from: data) //<-copying the data
let rawPtr = UnsafeRawPointer(uint8Ptr)
var digest = UInt8
CC_SHA1(rawPtr, CC_LONG(data.count), &digest)
let output = NSMutableString(capacity: Int(CC_SHA1_DIGEST_LENGTH))
for byte in digest{
output.appendFormat("%02x", byte)
}
return output as String
}