美文网首页iOS 开发
iOS MD5处理字符串

iOS MD5处理字符串

作者: liyc_dev | 来源:发表于2017-02-15 10:51 被阅读16次

迁移自开源中国

32位MD5处理

- (NSString *)getMd5_32Bit {
    const char *cStr = [self UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, self.length, digest );
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [result appendFormat:@"%02x", digest[i]];
    return result;
}

这是NSString的一个分类(category),所以self.length 就是这个字符串的长度。

相关文章

网友评论

    本文标题:iOS MD5处理字符串

    本文链接:https://www.haomeiwen.com/subject/ckfqwttx.html