12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #ifndef __MD5__
- #define __MD5__
- #pragma once
- //////////////////////////////////////////////////////////////////////////
- // MD5的Context结构体;
- typedef struct
- {
- // 状态 (ABCD);
- UINT32 state[4];
- // 2进制位个数, modulo 2^64 (lsb first);
- UINT32 count[2];
- // 输入的缓冲区;
- UINT8 buffer[64];
- } MD5_CTX;
- class __declspec(dllexport) CMD5
- {
- public:
- CMD5(void);
- CMD5(IN CONST BYTE* szInput,IN CONST size_t& nInputLen);
- ~CMD5(void);
- private:
- // md5核心算法;
- void MD5Init(IN MD5_CTX* md5ctx);
- void MD5Update(IN MD5_CTX* md5ctx, IN UINT8* Input, IN CONST size_t& InputLen);
- void MD5Transform(IN UINT32 state[4], IN UINT8 block[64] );
- void MD5Final(IN UINT8 digest[16], IN MD5_CTX* md5ctx);
- void Decode(IN UINT32 *output, IN UINT8 *input, IN CONST size_t& len);
- void Encode(IN UINT8 *output, IN UINT32 *input, IN CONST size_t& len);
- private:
- // md5封装;
- // 计算md5是否成功;
- BOOL m_bValidDigest;
- // md5计算后的结果值;
- UINT8 m_digest[16];
- // 将md5数值转化为16进制字符串;
- TCHAR m_digestStr[33];
- // 要计算的字符串;
- BYTE* m_pInputText;
- // 要计算的字符串长度;
- size_t m_nInputLen;
- // 计算出md5转化结果;
- BOOL CalcDigest();
- // 对外接口;
- public:
- void SetBYTEText(IN CONST BYTE* szInput,IN CONST size_t& nInputLen);
- CONST TCHAR* GetMD5Digest();
- };
- #endif
|