Swift sha1加密

AES/RSA/MD2/MD5/SHA1/SHA128/SHA384/SHA512 in Swift
可以参考github: https://github.com/adow/SecrecySwift
https://github.com/SwiftP2P/SwiftSSL

swift实现sha1加密算法,需要现在beidge-header文件中添加下述语句

// sha1
#import 

sha1

import UIKit
 
extension String{
    func sha1() -> String{
        let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!
        var digest = [UInt8](count:Int(CC_SHA1_DIGEST_LENGTH),repeatedValue:0)
        CC_SHA1(data.bytes, CC_LONG(data.length), &digest)
         
        let output = NSMutableString(capacity: Int(CC_SHA1_DIGEST_LENGTH))
        for byte in digest{
            output.appendFormat("%02x", byte)
        }
        return output as String
    }
}

你可能感兴趣的:(Swift sha1加密)