Skip to content

Instantly share code, notes, and snippets.

@lerno
Created September 18, 2014 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lerno/8eb04509fc425fe274cf to your computer and use it in GitHub Desktop.
Save lerno/8eb04509fc425fe274cf to your computer and use it in GitHub Desktop.
//C
unsigned char result[CC_MD5_DIGEST_LENGTH];
const char *cString = [self UTF8String];
CC_MD5(cString, (CC_LONG)strlen(cString), result);
return bytesToHexString(result, CC_MD5_DIGEST_LENGTH);
//Swift
let digestLength = 16
var result = Array<UInt8>(count: digestLength, repeatedValue: 0)
let cString = cStringUsingEncoding(NSUTF8StringEncoding)!
CC_MD5(cString, UInt32(cString.count - 1), &result)
return String.bytesToHex(result)
@mpw
Copy link

mpw commented Sep 18, 2014

How about:

self utf8data md5 toHex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment