IOS에서 사용하는 Hash 알고리즘 중 하나인 MD5 사용해 보기
<header Import>
<function Code>
<use case>
<result>
생각보다 간단하네 ^^:
<header Import>
#import <CommonCrypto/CommonDigest.h>
<function Code>
#pragma mark -
#pragma mark MD5 Convert
+(NSString *)strToMD5:(NSString *)inStr
{
const char *inUTF8_str = [inStr UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(inUTF8_str, strlen(inUTF8_str), result);
NSMutableString *hash = [NSMutableString string];
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[hash appendFormat:@"%02X", result[i]];
return [hash lowercaseString];
}
<use case>
NSString *md5Str = [Util strToMD5:@"test"];
<result>
md5Str = "098f6bcd4621d373cade4e832627b4f6"
생각보다 간단하네 ^^: