0

i have been looking at the following (I am pretty new to IOS so any help would be gratefully appreciated).

How to convert string to MD5 hash using ios swift

And with the explanation of code used for Swift 2.2 from Hugo Alonso i am having problems actually using the function and declaring a string that is then hashed.

Code is below

struct MD5Digester {
// return MD5 digest of string provided
static func digest(string: String) -> String? {

    guard let data = string.dataUsingEncoding(NSUTF8StringEncoding) else { return nil }

    var digest = [UInt8](count: Int(CC_MD5_DIGEST_LENGTH), repeatedValue: 0)

    CC_MD5(data.bytes, CC_LONG(data.length), &digest)

    return (0..<Int(CC_MD5_DIGEST_LENGTH)).reduce("") { $0 + String(format: "%02x", digest[$1]) }
  }
}

Any help is appreciated.

Thanks

Community
  • 1
  • 1

0 Answers0