openssl的Md5计算笔记
2016-03-24 15:42
239 查看
#include <openssl/md5.h> #include <iostream> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <boost/algorithm/string.hpp> using std::cout ; using std::endl ; std::string downgadget::Downloader_c::FileDigest(const std::string &file) { FILE *fd=fopen(file.c_str(),"r"); if(!fd){ return std::string(""); } MD5_CTX c; unsigned char md[16]; int len; char tmp[3]={'\0'}, md5buf[33]={'\0'}; unsigned char buffer [1024]={'\0'}; MD5_Init(&c); while( 0 != (len = fread(buffer, 1, 1024, fd) ) ) { MD5_Update(&c, buffer, len); } MD5_Final(md,&c); for(int i = 0; i < 16; i++) { sprintf(tmp,"%02X",md[i]); strcat(md5buf,tmp); } std::string tmpStr(md5buf); boost::to_lower(tmpStr); cout<<tmpStr<<endl; fclose(fd); return tmpStr; }
相关文章推荐
- ssh-key的生成、分发及配置
- 淘宝架构框架
- Linux初学者成为高手的学习步骤和建议
- 嵌入式linux的tftp安装配置及tftp命令用法
- linux命令---awk进阶
- Hadoop-写入数据的几种方式
- Hbase与Hadoop结合出现的jar包冲突问题
- Linux下undefined reference to ‘pthread_create’问题解决
- wget 递归下载整个网站(网站扒皮必备)
- 为什么要使用CMake+VS编译OpenCV的源码
- linux下设置环境变量的三种方法
- 给windows linux cicos增加路由的方法
- linux遍历文件夹源码
- CentOS 6.4 下 sync
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
- docker supervisord
- Linux文件权限
- docker 开机重启
- 编译安装apache2.4.18遇到的问题以及解决办法
- linux下批量替换文件内容