導(dǎo)入#import<CommonCrypto/CommonDigest.h>
//SHA
- (NSString* )SHA{
? ? const char *cstr = [self cStringUsingEncoding:NSUTF8StringEncoding];
? ? NSData *data = [NSData dataWithBytes:cstr length:self.length];
? ? //使用對應(yīng)的CC_SHA1,CC_SHA256,CC_SHA384,CC_SHA512的長度分別是20,32,48,64
? ? uint8_t digest[CC_SHA1_DIGEST_LENGTH];
? ? //使用對應(yīng)的CC_SHA256,CC_SHA384,CC_SHA512
? ? CC_SHA1(data.bytes, data.length, digest);
? ? NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
? ? for(int i =0; i<CC_SHA1_DIGEST_LENGTH ;i ++){
? ? ? ?[outputappendFormat:@"%02x", digest[i]];
????}
? ? NSLog(@"%@",output);
? ? return output;
}