MD5.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef MD5_H
  2. #define MD5_H
  3. /* Type define */
  4. typedef unsigned char byte;
  5. typedef unsigned int uint32;
  6. /* MD5 declaration. */
  7. class MD5 {
  8. public:
  9. MD5();
  10. MD5(const void* input, size_t length);
  11. MD5(const std::string& str);
  12. MD5(std::ifstream& in);
  13. void update1(const void* input, size_t length);
  14. void update2(std::basic_ifstream<char> str);
  15. void update3(std::ifstream& in);
  16. void update(const std::string& str);
  17. const byte* digest();
  18. std::string toString();
  19. void reset();
  20. private:
  21. void update(const byte* input, size_t length);
  22. void final();
  23. void transform(const byte block[64]);
  24. void encode(const uint32* input, byte* output, size_t length);
  25. void decode(const byte* input, uint32* output, size_t length);
  26. std::string bytesToHexString(const byte* input, size_t length);
  27. /* class uncopyable */
  28. MD5(const MD5&);
  29. MD5& operator=(const MD5&);
  30. private:
  31. uint32 _state[4]; /* state (ABCD) */
  32. uint32 _count[2]; /* number of bits, modulo 2^64 (low-order word first) */
  33. byte _buffer[64]; /* input buffer */
  34. byte _digest[16]; /* message digest */
  35. bool _finished; /* calculate finished ? */
  36. static const byte PADDING[64]; /* padding for calculate */
  37. static const char HEX[16];
  38. enum { BUFFER_SIZE = 1024 };
  39. };
  40. #endif /*MD5_H*/