亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C++/CLI 生成的 HMACSHA256 Hash key

C++/CLI 生成的 HMACSHA256 Hash key

繁花不似錦 2021-06-28 21:50:02
C++/CLI 函數我正在使用 C++/CLI 生成哈希鍵,并通過網絡將數據和哈希鍵發送到用 Java 編碼的其他應用程序。但是 Java 應用程序會生成不同的 HashKey。是否由于不同服務器上的不同應用程序導致哈希鍵不同?知道我哪里出錯了嗎?提前致謝。 char* EncodeData(char* ap_key, char*  ap_sourceData)     {        char* lp_data_to_send = NULL;        int key_len = strlen(ap_key);        String^ lv_data = gcnew String(ap_sourceData);//Getting Data in System String        array<Byte>^ lv_main_data   = Encoding::UTF8->GetBytes(lv_data);//Encoding to UTF-8        array<Byte>^key = gcnew array< Byte >(key_len + 2);        Marshal::Copy((IntPtr)ap_key, key, 0, key_len); //Copy key in System Array Byte        // Initialize the keyed hash object.        HMACSHA256^ myhmacsha256 = gcnew HMACSHA256(key);        // Compute the hash of the input file.        array<Byte>^hashValue = myhmacsha256->ComputeHash(lv_main_data);        String^ lv_hex_convert = BitConverter::ToString(hashValue)->Replace("-","");    //Converted to Hexadecimal and replacing '-' with ""        Console::WriteLine(lv_hex_convert);//Converted Hexadecimal Hashkey           //Converting to Char*            lp_data_to_send = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(lv_hex_convert);//Converting again to char* to be send to Calling Function          myhmacsha256->Clear(); //myhmacsha256 clear Instance          return lp_data_to_send;//Return Char*    }int main()            {                //Secret Key shared by C++/CLi application and Java Application                String ^ lv_key_g = " My Secret Key";                char lv_sourceData[] = { "My data" };                char lv_destinationData[512] = { "" };                char* lp_ret = NULL;                array<Byte>^secretkey = gcnew array<Byte>(65); //Declaring Array                //Converting to UTF-8                 secretkey = Encoding::UTF8->GetBytes(lv_key_g);                /*Converting to char* */
查看完整描述

1 回答

?
青春有我

TA貢獻1784條經驗 獲得超8個贊

return lp_data_to_send;//Return Char*將返回一個懸空指針,您可能應該返回一個引用計數的字符串lv_hex_convert。另一個可疑的事情是密鑰比所需的長 2 個字節。


查看完整回答
反對 回復 2021-07-07
  • 1 回答
  • 0 關注
  • 273 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號