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:
|
iOS使用MD5 - 字符串加密至MD5&获取文件MD5的更多相关文章
- C#获取文件MD5字符串
备注 哈希函数将任意长度的二进制字符串映射为固定长度的小型二进制字符串.加密哈希函数有这样一个属性:在计算不大可能找到散列为相同的值的两个不同的输入:也就是说,两组数据的哈希值仅在对应的数据也匹配时才 ...
- MD5字符串加密
MD5字符串加密 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护.该算法的文件号为RFC 132 ...
- JAVA中获取文件MD5值的四种方法
JAVA中获取文件MD5值的四种方法其实都很类似,因为核心都是通过JAVA自带的MessageDigest类来实现.获取文件MD5值主要分为三个步骤,第一步获取文件的byte信息,第二步通过Messa ...
- QT 获取文件MD5值
/* 方法1 */ QFile theFile(fileNamePath); theFile.open(QIODevice::ReadOnly); QByteArray ba = QCryptogra ...
- c#获取文件MD5算法
//获取文件MD5算法 private static string GetMD5FromFile(string fileName) { try { FileStream file = new File ...
- C# 获取文件MD5值的方法
可用于对比文件是否相同 /// <summary> /// 获取文件MD5值 /// </summary> /// <param name="fileName& ...
- 基于js-spark-md5前端js类库,快速获取文件Md5值
js-spark-md5是歪果仁开发的东西,有点多,但是我们只要一个js文件即可,具体类包我存在自己的oschina上,下载地址:https://git.oschina.net/jianqingwan ...
- 获取文件MD5值(JS、JAVA)
文章HTML代码翻译于地址:https://www.cnblogs.com/linyihai/p/7040786.html 文件MD5有啥用? 文 ...
- iOS字符串加密至MD5&及获取文件MD5
iOS 字符串加密至MD5 #import <CommonCrypto/CommonDigest.h> + (NSString *) md5:(NSString *)str { const ...
随机推荐
- Python + Selenium 自动化环境搭建过程
1. 所需组建 1.1 Selenium for python 1.2 Python 1.3 Notepad++ 作为刚初学者,这里不建议使用Python IDE工具,选择一个功能强大的记事本 ...
- dotfiles项目
1.dotfile介绍 在linux中的各种软件配置文件大多是以.开头,以rc结尾,在第一次使用某一个软件比如vim的时候,通常会花大量时间配置,将所有的配置文件放到同一个目录下,方便在多台机器上同步 ...
- Python基础-week08 并发编程
一 背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所 ...
- tomcat源码分析一
废话少说,拉代码,导入eclipse开干,具体步骤可以参考http://hi.baidu.com/hateeyes/blog/item/7f44942a20ad8f9d023bf66d.html 下面 ...
- mongodb的安装和sql操作
mongodb安装环境:centos6.5https://www.mongodb.org/dl/linux/x86_64wget https://fastdl.mongodb.org/linux/mo ...
- 【bzoj1415】[Noi2005]聪聪和可可 期望记忆化搜索
题目描述 输入 数据的第1行为两个整数N和E,以空格分隔,分别表示森林中的景点数和连接相邻景点的路的条数. 第2行包含两个整数C和M,以空格分隔,分别表示初始时聪聪和可可所在的景点的编号. 接下来E行 ...
- C#添加编译时间
using System.Reflection;using UnityEngine;using System.Collections; [assembly:AssemblyVersion( " ...
- hdu5834 Magic boy Bi Luo with his excited tree 【树形dp】
题目链接 hdu5834 题解 思路很粗犷,实现很难受 设\(f[i][0|1]\)表示向子树走回来或不回来的最大收益 设\(g[i][0|1]\)表示向父亲走走回来或不回来的最大收益 再设\(h[i ...
- BZOJ1491 [NOI2007]社交网络 【floyd】
题目 在社交网络(socialnetwork)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题. 在一个社交圈子里有n个人,人与人之间有不同程度的关系.我们将这个关系网络对应到一 ...
- python数据结构之字典
1.python字典的定义 1.用大括号{},以逗号分隔每个键值对,键与值之间用冒号连接 2.键:需要不可变的数据结构,值可以是任意的数据对象 3.字典是无序的,键在字典中必须是唯一,在字典中取值的方 ...