获取md5的高效的方法
来源:互联网 发布:网络排名优化软件 编辑:程序博客网 时间:2024/06/05 15:29
CFStringRef FileMD5HashCreateWithPath(CFStringRef filePath,
size_t chunkSizeForReadingData) {
// Declare needed variables
CFStringRef result = NULL;
CFReadStreamRef readStream = NULL;
// Get the file URL
CFURLRef fileURL =
CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
(CFStringRef)filePath,
kCFURLPOSIXPathStyle,
(Boolean)false);
if (!fileURL) goto done;
// Create and open the read stream
readStream =CFReadStreamCreateWithFile(kCFAllocatorDefault,
(CFURLRef)fileURL);
if (!readStream) goto done;
bool didSucceed = (bool)CFReadStreamOpen(readStream);
if (!didSucceed) goto done;
// Initialize the hash object
CC_MD5_CTX hashObject;
CC_MD5_Init(&hashObject);
// Make sure chunkSizeForReadingData is valid
if (!chunkSizeForReadingData) {
chunkSizeForReadingData =4096;
}
// Feed the data to the hash object
bool hasMoreData = true;
while (hasMoreData) {
uint8_t buffer[chunkSizeForReadingData];
CFIndex readBytesCount = CFReadStreamRead(readStream,
(UInt8 *)buffer,
(CFIndex)sizeof(buffer));
if (readBytesCount == -1) break;
if (readBytesCount == 0) {
hasMoreData =false;
continue;
}
CC_MD5_Update(&hashObject,
(constvoid *)buffer,
(CC_LONG)readBytesCount);
}
// Check if the read operation succeeded
didSucceed = !hasMoreData;
// Compute the hash digest
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5_Final(digest, &hashObject);
// Abort if the read operation failed
if (!didSucceed) goto done;
// Compute the string result
char hash[2 * sizeof(digest) + 1];
for (size_t i = 0; i < sizeof(digest); ++i) {
snprintf(hash + (2 * i), 3, "%02x", (int)(digest[i]));
}
result =CFStringCreateWithCString(kCFAllocatorDefault,
(constchar *)hash,
kCFStringEncodingUTF8);
done:
if (readStream) {
CFReadStreamClose(readStream);
CFRelease(readStream);
}
if (fileURL) {
CFRelease(fileURL);
}
return result;
}
- 获取md5的高效的方法
- 获取文件Md5的方法
- iOS上获取文件md5的方法
- 获取apk证书MD5值的方法
- 获取apk证书MD5值的方法
- iOS上获取文件md5的方法
- 获取应用签名MD5指纹的方法
- 获取apk证书MD5值的方法
- 获取apk证书MD5值的方法
- AndroidStudio获取MD5,SHA1的方法
- 高效获取随机数组的方法
- shell高效获取分割字符串的方法?
- 获取文件的md5
- MD5值的获取
- 获取文件的md5
- 获取文件的MD5
- 获取文件的md5
- 获取文件的MD5
- C# .NET打包发布
- 思想决定行为;行为决定习惯;习惯决定性格;性格决定命运
- 生产者消费者完整代码
- Mysql事务与锁的好文章记录
- 每天一道算法题5 判断整数序列是不是二元查找树的后序遍历结果
- 获取md5的高效的方法
- SQL Server 在RAID 10 vs. RAID 5性能
- 2000 动态 行列转换
- jQuery Moblie 页面模版(基础)
- 每天一道算法题6 求1+2+...+n
- UIApplication sharedApplication详细解释-IOS
- 使用反射检查和实例化泛型类型
- 每天一道算法题7 查找链表中倒数第k个结点
- 在DOS界面下如何调用HEVC编码器跟解码器