Hi,
I am writing a swift build script for my app which needs to calculate md5 checksum of a string. The issue I am facing is I am unable to link to CommonCrypto so i can use CC's functions. Any advice would be helpful.
P.S. My script looks something like this
#!/usr/bin/swift
import Foundation
import Darwin
/*
... code code code
*/
// Here we get a compile error CC_MD5_DIGEST_LENGTH & CC_MD5 are unresolved udentifiers
extension String {
func md5() -> String! {
let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen = CUnsignedInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
CC_MD5(str!, strLen, result)
let hash = NSMutableString()
for i in 0..<digestLen {
hash.appendFormat("%02x", result[i])
}
result.destroy()
return String(format: hash as String)
}
}