taoCMS是基于php+sqlite/mysql的国内最小(100Kb左右)的功能完善、开源免费的CMS管理系统

Object-C MD5与PHP md5、md5_file函数的差异说明

2017-04-16
If You do echo md5('hello') in PHP You would receive a 32 char long string, but when You use Your code snippet in ObjC, You transform the string chars to the HEX format (by using the formater %02x) - see here https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265 and here: Unsigned Char Array to Hex Representation NSString.

And You use only half the MD5 string chars to create this HEX formated string... Either return the result immediately or do the same HEX transformation in PHP :-)



The function found in this answer does the job perfectly in my testing:

#import <CommonCrypto/CommonDigest.h>

...
+ (NSString*)md5HexDigest:(NSString*)input {
const char* str = [input UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, strlen(str), result);

NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}

...
Matched up with PHP's implementation exactly. It originally comes from the Facebook Connect source code.


类别:未分组 | 阅读:238753 | 评论:0 | 标签:object-c ios

想收藏或者和大家分享这篇好文章→

“Object-C MD5与PHP md5、md5_file函数的差异说明”共有0条留言

发表评论

姓名:

邮箱:

网址:

验证码:

公告

taoCMS发布taoCMS 3.0.2(最后更新21年03月15日),请大家速速升级,欢迎大家试用和提出您宝贵的意见建议。

捐助与联系

☟请使用新浪微博联系我☟

☟在github上follow我☟

标签云