Last active
August 29, 2015 14:23
-
-
Save alfredoreduarte/0afa20ba5e23bd068523 to your computer and use it in GitHub Desktop.
Obj-c Generate MD5 from string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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