iOS开发-MD5加密SHA1加密
Posted 小K’s Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发-MD5加密SHA1加密相关的知识,希望对你有一定的参考价值。
1.MD5加密
///MD5加密
+ (NSString *)md5:(NSString *)inputString{
const char *cStr = [inputString UTF8String];
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, (int)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]];
///转变成大写
NSString *putString = [output uppercaseString];
return putString;
}
1.SHA1加密
///sha1加密
+(NSString *)sha1:(NSString *)inputString{
const char *cstr = [inputString cStringUsingEncoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithBytes:cstr length:inputString.length];
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes, (CC_LONG)data.length, digest);
NSMutableString* result = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
[result appendFormat:@"%02x", digest[i]];
}
return result;
}
以上是关于iOS开发-MD5加密SHA1加密的主要内容,如果未能解决你的问题,请参考以下文章