diff --git a/cpp_ext/tcp_ssl_password.cpp b/cpp_ext/tcp_ssl_password.cpp new file mode 100644 index 0000000..525e9aa --- /dev/null +++ b/cpp_ext/tcp_ssl_password.cpp @@ -0,0 +1,33 @@ +#include "tcp_ssl_password.hpp" + +#include +#include +#include + +namespace netcore { + +static std::string md5_hex(const std::string& input) { + MD5_CTX ctx; + MD5_Init(&ctx); + MD5_Update(&ctx, input.data(), input.size()); + + unsigned char digest[MD5_DIGEST_LENGTH]; + MD5_Final(digest, &ctx); + + std::ostringstream oss; + oss << std::hex << std::setfill('0'); + for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { + oss << std::setw(2) << static_cast(digest[i]); + } + return oss.str(); +} + +std::string calculate_tcp_ssl_password(const std::string& device_id, const std::string& iccid) { + std::string md5_device_hex = md5_hex(device_id); + if (!iccid.empty()) { + md5_device_hex += iccid; + } + return md5_hex(md5_device_hex); +} + +} // namespace netcore diff --git a/cpp_ext/tcp_ssl_password.hpp b/cpp_ext/tcp_ssl_password.hpp new file mode 100644 index 0000000..71ecbfd --- /dev/null +++ b/cpp_ext/tcp_ssl_password.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace netcore { + std::string calculate_tcp_ssl_password(const std::string& device_id, const std::string& iccid); +}