59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <fstream>
|
|
|
|
#ifdef EARTHWORM_EXPORT
|
|
#define DLLIMPEXP __declspec(dllexport)
|
|
#else
|
|
#define DLLIMPEXP __declspec(dllimport)
|
|
#endif
|
|
|
|
typedef unsigned char byte;
|
|
typedef unsigned int uint32;
|
|
|
|
class DLLIMPEXP ImpMD5
|
|
{
|
|
public:
|
|
|
|
ImpMD5();
|
|
ImpMD5(const void* input, size_t length);
|
|
ImpMD5(const std::string& str);
|
|
ImpMD5(std::ifstream& in);
|
|
|
|
void update(const void* input, size_t length);
|
|
void update(const std::string& str);
|
|
void update(const std::wstring& str);
|
|
void update(std::ifstream& in);
|
|
|
|
const byte* digest();
|
|
|
|
std::string toString();
|
|
std::string toString16();
|
|
std::wstring toStringW();
|
|
std::wstring toString16W();
|
|
void reset();
|
|
|
|
private:
|
|
void update(const byte* input, size_t length);
|
|
void final();
|
|
void transform(const byte block[64]);
|
|
void encode(const uint32* input, byte* output, size_t length);
|
|
void decode(const byte* input, uint32* output, size_t length);
|
|
std::string bytesToHexString(const byte* input, size_t length);
|
|
|
|
ImpMD5(const ImpMD5&);
|
|
ImpMD5& operator=(const ImpMD5&);
|
|
|
|
private:
|
|
uint32 m_state[4]; /* state (ABCD) */
|
|
uint32 m_count[2]; /* number of bits, modulo 2^64 (low-order word first) */
|
|
byte m_buffer[64]; /* input buffer */
|
|
byte m_digest[16]; /* message digest */
|
|
bool m_finished; /* calculate finished ? */
|
|
|
|
static const byte PADDING[64]; /* padding for calculate */
|
|
static const char HEX[16];
|
|
enum eBufferSize{ BUFFER_SIZE = 1024 };
|
|
}; |