Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

str 转 md5

 

 

 1 @interface NSString (MD5)
 2 
 3 + (NSString *)md5To32bit:(NSString *)str;
 4 
 5 @end
 6 
 7 
 8 @implementation NSString (MD5)
 9 
10 + (NSString *)md5To32bit:(NSString *)str {
11     
12     const char *cStr = [str UTF8String];
13     unsigned char digest[CC_MD5_DIGEST_LENGTH];
14     CC_MD5( cStr, (CC_LONG)strlen(cStr),digest );
15     NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
16     for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
17         [result appendFormat:@"%02x", digest[i]];
18     return result;
19 }
20 
21 @end

 

posted on 2017-08-23 10:52  Sinner_Yun  阅读(190)  评论(0编辑  收藏  举报

导航