iOS-聊聊加密的那些事

xiaoxiao2021-02-28  91

MD5加密

情景:网页加载缓存可能会用到NSURLCache,每次请求会返回一个URLCacheResponse.现在我们需要将每个URL保存在Caches文件中,为了加密,要对每个URL使用MD5加密技术。相应的代码段是:

+ (NSString *)md5Hash:(NSString *)str { const char *cStr = [str UTF8String]; unsigned char result[16]; CC_MD5( cStr, (CC_LONG)strlen(cStr), result ); NSString *md5Result = [NSString stringWithFormat: @"xxxxxxxxxxxxxxxx", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15] ]; return md5Result; }
转载请注明原文地址: https://www.6miu.com/read-53224.html

最新回复(0)