there are a few threads here on stackoverflow about this topic, but I can't get it working. So I hope you can help me:
I created a header-file called: Crypto.h and it only contains this line:
#import <CommonCrypto/CommonCrypto.h>
Further more, I have a file called StringExtension.swift and it contains this code:
import Foundation
extension String {
func sha256() -> String {
let data = self.dataUsingEncoding(NSUTF8StringEncoding)!
var digest = [UInt8](count:Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0)
CC_SHA256(data.bytes, CC_LONG(data.length), &digest)
let hexBytes = digest.map { String(format: "%02hhx", $0) }
return hexBytes.joinWithSeparator("")
}
}
I got the code from here: How to crypt string to sha1 with Swift? I found on another website, that I can replace sha1 with sha256 if you want to use sha256.
But I errors like this: Use of unresolved identifier 'CC_SHA256_DIGEST_LENGTH'
What am I doing wrong?