iOS开发之MD5加密的使用

直接调用这个方法,传一个字符串进去,返回的就是经过MD5加密的密文

- (NSString *)MD5ByAStr:(NSString *)str
{
    const char *variable1 = [str UTF8String];
    unsigned char variable2[CC_MD5_DIGEST_LENGTH];
    CC_MD5(variable1, (CC_LONG)strlen(variable1), variable2);
    
    NSMutableString *variable3 = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
    for (NSInteger i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [variable3 appendFormat:@"%02x", variable2[i]];
    }
    return variable3;
}


你可能感兴趣的:(ios开发)