forked from owasp-modsecurity/ModSecurity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd5.cc
40 lines (24 loc) · 778 Bytes
/
md5.cc
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
#include "src/utils/md5.h"
#include "others/mbedtls/md5.h"
namespace modsecurity {
namespace Utils {
std::string Md5::hexdigest(const std::string& input) {
unsigned char digest[16];
mbedtls_md5(reinterpret_cast<const unsigned char *>(input.c_str()),
input.size(), digest);
char buf[33];
for (int i = 0; i < 16; i++) {
sprintf(buf+i*2, "%02x", digest[i]);
}
return std::string(buf, 32);
}
std::string Md5::digest(const std::string& input) {
unsigned char output[16];
std::string ret;
mbedtls_md5(reinterpret_cast<const unsigned char *>(input.c_str()),
input.size(), output);
ret.assign(reinterpret_cast<const char *>(output), 16);
return ret;
}
} // namespace Utils
} // namespace modsecurity