From e90ea5154ce6972e5cc6836fb2d400bd31b03f9e Mon Sep 17 00:00:00 2001 From: gcw_4spBpAfv Date: Fri, 15 May 2026 14:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0cpp=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpp_ext/tcp_ssl_password.cpp | 33 +++++++++++++++++++++++++++++++++ cpp_ext/tcp_ssl_password.hpp | 7 +++++++ 2 files changed, 40 insertions(+) create mode 100644 cpp_ext/tcp_ssl_password.cpp create mode 100644 cpp_ext/tcp_ssl_password.hpp 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); +}