iPhone:用于将Web图像(url)存储为文件(哈希文件名)的快速哈希函数 [英] iPhone: fast hash function for storing web images (url) as files (hashed filenames)

查看:156
本文介绍了iPhone:用于将Web图像(url)存储为文件(哈希文件名)的快速哈希函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是快速哈希函数可用于iPhone哈希Web网址(图像)?

What is a fast hash function available for the iPhone to hash web urls (images)?

我想将缓存的网络映像存储为一个以散列作为文件名的文件,因为我认为原始网址可能包含可能导致问题的奇怪字符在文件系统上。

I'd like to store the cached web image as a file with a hash as the filename, because I suppose the raw web url could contain strange characters that could cause problems on the file system.

散列函数不需要加密,但它肯定需要快速。

The hash function doesn't need to be cryptographic, but it definitely needs to be fast.

strong>示例:

Example:

输入: http://www.calumetphoto.com/files/iccprofiles/icc-test-image .jpg

输出: 3573ed9c4d3a5b093355b2d8a14​​68509

这是通过使用MD5(),但由于我不知道那个话题很多,我不知道它是否过度( - >慢)。

This was done by using MD5(), but since I don't know much about that topic I don't know if it is overkill (-> slow).

推荐答案

MD5可能出于安全目的而损坏,但它适用于您描述的情况。 这里有一个线程如何在iPhone上实现它。查看Vroomtrap的帖子。对于后代,这里是我自己的代码版本:

MD5 may be broken for security purposes, but it works well for the situation you describe. Here's a thread on how to implement it on iPhone. Check out Vroomtrap's post. For posterity, here's my own version of that code:

- (NSString *)MD5Hash {
    const char *cStr = [self UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];

    CC_MD5( cStr, strlen(cStr), result );

    return [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
        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] ];
}

您需要导入 CommonCrypto / CommonDigest .h 标题。

这篇关于iPhone:用于将Web图像(url)存储为文件(哈希文件名)的快速哈希函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆