From 38abf34d41f627a4b84ec48cfbf571cc0c445a60 Mon Sep 17 00:00:00 2001 From: xx Date: Thu, 13 Mar 2025 17:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0hmac=5Fsha256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/codec.cpp | 7 ++++++- src/module/codec.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/module/codec.cpp b/src/module/codec.cpp index 0b84ad0..826cde8 100644 --- a/src/module/codec.cpp +++ b/src/module/codec.cpp @@ -50,6 +50,10 @@ std::string module::codec::sha256(const std::string_view& value) { return ylib::codec::sha256(ylib::buffer(value.data(), value.length())).to_hex(); } +std::string module::codec::hmac_sha256(const std::string& key, const std::string_view& value) +{ + return ylib::codec::hmac_sha256(key,ylib::buffer(value.data(), value.length())).to_hex(); +} void module::codec::regist(sol::state* lua) { lua->new_usertype("fw_codec", @@ -59,6 +63,7 @@ void module::codec::regist(sol::state* lua) "to_gbk", &module::codec::to_gbk, "md5", &module::codec::md5, "sha1", &module::codec::sha1, - "sha256", &module::codec::sha256 + "sha256", &module::codec::sha256, + "hmac_sha256", &module::codec::hmac_sha256 ); } diff --git a/src/module/codec.h b/src/module/codec.h index fb8c84d..596ed1c 100644 --- a/src/module/codec.h +++ b/src/module/codec.h @@ -32,6 +32,7 @@ namespace module static std::string sha1(const std::string_view& value); static std::string sha256(const std::string_view& value); + static std::string hmac_sha256(const std::string& key,const std::string_view& value); static void regist(sol::state* lua); };