-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathmd5.h
72 lines (63 loc) · 1.64 KB
/
md5.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* .============.
* // M A K E / \
* // C++ DEV / \
* // E A S Y / \/ \
* ++ ----------. \/\ .
* \\ \ \ /\ /
* \\ \ \ /
* \\ \ \ /
* -============'
*
* Copyright (c) 2018 Hevake and contributors, all rights reserved.
*
* This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
* Use of this source code is governed by MIT license that can be found
* in the LICENSE file in the root of the source tree. All contributing
* project authors may be found in the CONTRIBUTORS.md file in the root
* of the source tree.
*/
#ifndef TBOX_CRYPTO_MD5_H_20221218
#define TBOX_CRYPTO_MD5_H_20221218
#include <cstdint>
#include <string>
namespace tbox {
namespace crypto {
/**
* MD5 计算器
*
* 使用示例:
* const char *str1 = "cpp-tbox, C++ Treasure Box,";
* const char *str2 = " is an event-based service application development library.";
*
* MD5 md5;
* md5.update(str1, strlen(str1));
* md5.update(str2, strlen(str2));
*
* uint8_t md5_digest[16];
* md5.finish(md5_digest);
*/
class MD5 {
public:
MD5();
public:
/**
* \brief 将明文数据喂给MD5,可重复进行
* \param plain_text_ptr 明文地址
* \param plain_text_len 明文长度
*/
void update(const void* plain_text_ptr, size_t plain_text_len);
/**
* \brief 结束运算,并获取结果
* \param digest 16字节长的结果输出地址
*/
void finish(uint8_t digest[16]);
private:
uint32_t count_[2];
uint32_t state_[4];
uint8_t buffer_[64];
bool is_finished_ = false;
};
}
}
#endif //TBOX_CRYPTO_MD5_H_20221218