计算文件的MD5值

来源:互联网 发布:官路淘宝全文免费阅读 编辑:程序博客网 时间:2024/05/18 00:32

使用openssl计算文件的MD5值

#include <fstream>#include <Windows.h>#include <iostream>#include <string>#include <iomanip>#include "openssl/md5.h" int main(){    char szFilepath[255] = { 0 };    GetModuleFileNameA( NULL, szFilepath, 255 );    strrchr( szFilepath, '\\' )[1] = 0;    string strFileName = szFilepath;    strFileName += "package.json";    {        std::ifstream fin(strFileName.c_str());        if (! fin.is_open())          {             cout << "Error opening file" << endl;            return 1;        }        string str;        MD5_CTX c;          unsigned char md5[17]={0};         MD5_Init(&c);        while(getline(fin,str))        {            MD5_Update(&c, str.c_str(), str.size());          }        MD5_Final(md5,&c);          for(int i = 0; i < 16; i++)              cout << hex << setw(2) << setfill('0') << (int)md5[i];        cout << endl ;        fin.close();        return 0;}
0 0
原创粉丝点击