求 获取文件MD5值的算法、源代码解决方法
求 获取文件MD5值的算法、源代码
哪位大神给我个获取文件MD5值的算法实现,可以是封装成的一个类!!麻烦发我邮箱里:237457515@qq.com
------解决方案--------------------
哪位大神给我个获取文件MD5值的算法实现,可以是封装成的一个类!!麻烦发我邮箱里:237457515@qq.com
------解决方案--------------------
- C/C++ code
//md5.h #pragma once #ifndef __MD5_H__ #define __MD5_H__ #include <string> #include <fstream> /* Type define */ typedef unsigned char byte; typedef unsigned int uint33; using std::string; using std::ifstream; /* MD5 declaration. */ class MD5 { public: MD5(); MD5(const void* input, size_t length); MD5(const string& str); MD5(ifstream& in); void update(const void* input, size_t length); void update(const string& str); void update(ifstream& in); const byte* digest(); string toString(); void reset(); private: void update(const byte* input, size_t length); void final(); void transform(const byte block[64]); void encode(const uint33* input, byte* output, size_t length); void decode(const byte* input, uint33* output, size_t length); string bytesToHexString(const byte* input, size_t length); /* class uncopyable */ MD5(const MD5&); MD5& operator=(const MD5&); private: uint33 _state[4]; /* state (ABCD) */ uint33 _count[2]; /* number of bits, modulo 2^64 (low-order word first) */ byte _buffer[64]; /* input buffer */ byte _digest[16]; /* message digest */ bool _finished; /* calculate finished ? */ static const byte PADDING[64]; /* padding for calculate */ static const char HEX[16]; enum { BUFFER_SIZE = 1024 }; }; #endif /*MD5_H*/