Skip to content

Instantly share code, notes, and snippets.

@alfredoreduarte
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save alfredoreduarte/0afa20ba5e23bd068523 to your computer and use it in GitHub Desktop.

Select an option

Save alfredoreduarte/0afa20ba5e23bd068523 to your computer and use it in GitHub Desktop.
Obj-c Generate MD5 from string
#import <CommonCrypto/CommonDigest.h>
- (NSString *)generateMD5:(NSString *)token{
const char *cStr = [token cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char digest[16];
CC_MD5( cStr, strlen(cStr), digest );
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment