iOS使用MD5 - 字符串加密至MD5&获取文件MD5
iOS 字符串加密至MD5
#import <CommonCrypto/CommonDigest.h> + (NSString *) md5:(NSString *)str
{
const char *cStr = [str UTF8String];
unsigned char result[];
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[], result[], result[], result[],
result[], result[], result[], result[],
result[], result[], result[], result[],
result[], result[], result[], result[]
];
}
iPhone处理大文件检测MD5的代码
+(NSString*)fileMD5:(NSString*)path
{
NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:path];
if( handle== nil ) return @"ERROR GETTING FILE MD5"; // file didnt exist CC_MD5_CTX md5; CC_MD5_Init(&md5); BOOL done = NO;
while(!done)
{
NSData* fileData = [handle readDataOfLength: CHUNK_SIZE ];
CC_MD5_Update(&md5, [fileData bytes], [fileData length]);
if( [fileData length] == ) done = YES;
}
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5_Final(digest, &md5);
NSString* s = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[], digest[],
digest[], digest[],
digest[], digest[],
digest[], digest[],
digest[], digest[],
digest[], digest[],
digest[], digest[],
digest[], digest[]];
return s;
}
In my project i need to get the MD_5 hash code of the file in iphone. uptill now i have found the following code to get md_5 of any image/any file.
using this code to get the ByteContent of the image and then get the md_5 of that image byte array string
now i am getting a hash code succesfully But when on the web side i get the md_5 hash code of same file then it gives me diferent hash code. in Web side i am using PHP code
this PHP code gives me differnet hash code and iphone code gives me different hash code for same image. Please tell me what can be the problem.. Thanks alot! |
|
|
There are 2 causes. The first is because
The second cause is because of the PNG → raw image → PNG process. There is no guarentee that the same image will compress to the same PNG representation in different libraries, and of course you'll have different MD5. You could just avoid reading the file as image altogether, as it's possible read the file directly as data:
|
最新文章
- Xamarin+Prism开发详解四:简单Mac OS 虚拟机安装方法与Visual Studio for Mac 初体验
- HDFS Federation (读书笔记)
- 尝试自己翻译了FreeCodeCamp的文章,技术方面多认识了几种技术,文章标题:Transparency in Action Free Code Camp is Now Open Source
- [Bug]枚举数组,并找到某些元素删除
- 关于使用TP-Link桥接小米路由器
- scp命令[转]
- 安卓第九天笔记-Activity
- VS编程中找不到Microsoft.Office.Core、Microsoft.Office.Interop.Word和VBIDE
- 小例子(二)、winform窗体间的关系
- wordpress+php+mysql 配置
- VC7 HTML Dialog开发实例讲解
- How to change pager CSS in CGridView CListView in Yii
- [置顶] 自己写sqlhelper类
- OCP读书笔记(25) - 题库(ExamE)
- Alpha冲刺No.6
- 判断系统是64位还是32位的bat方法
- maven build pulgin
- mongols的反向代理和负载均衡功能
- Session &;cookie introduction,usage
- DTO的问题
热门文章
- leetcode 【 Plus One 】python 实现
- leetcode 【 Add Two Numbers 】 python 实现
- [python][django学习篇][9]设计正在博客视图(3)
- ci日志记录
- NSURLSession使用模板和AFNetworking使用模板(REST风格)
- mysql数据库无法插入中文字符
- cf 843 D Dynamic Shortest Path [最短路+bfs]
- FTB操作
- bzoj 2435 dfs处理
- 洛谷P3045 [USACO12FEB]牛券Cow Coupons