mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-17 01:51:52 +03:00
41 lines
778 B
C++
41 lines
778 B
C++
|
|
|
|
#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
|
|
|