哈希算法代码如下:
需要导入头文件
#import <CommonCrypto/CommonDigest.h>
然后代码就可以开始了
+ (NSString *)sha1:(NSString *)inputString{
NSData *data = [inputString dataUsingEncoding:NSUTF8StringEncoding];
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes,(unsigned int)data.length,digest);
NSMutableString *outputString = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
[outputString appendFormat:@"%02x",digest[i]];
}
return [outputString lowercaseString];
}