iOS sha1加密算法

 1 //sha1加密方式
 2 +(NSString *)sha1:(NSString *)input
 3 {
 4     //const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding];
 5     //NSData *data = [NSData dataWithBytes:cstr length:input.length];
 6 //    input = [input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 7     NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding];
 8     
 9     uint8_t digest[CC_SHA1_DIGEST_LENGTH];
10     
11     CC_SHA1(data.bytes, (unsigned int)data.length, digest);
12     
13     NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
14     
15     for(int i=0; i<CC_SHA1_DIGEST_LENGTH; i++) {
16         [output appendFormat:@"%02X", digest[i]];
17     }
18     
19     return output;
20 }

 

posted @ 2017-02-20 09:08  福泽小院  阅读(323)  评论(0编辑  收藏  举报