如果 key_text 超过 64 个字符,则 HMacSha256 计算错误。应该如何纠正?
字符串 text = "你好";
string key_text = "12345678901234567890123456789012345678901234567890123456789012345678901234";
https://www.devglan.com/online-tools/hmac-sha256-online-> 7558a77ff19ed6cb4777355e4bbc4772759a8130e1bb0913ba62b88411fdbaf8
测试脚本 -> 2025.02.27 22:28:43.792 Sha256TestFile (EURUSD,M5) 6d8ee9dc1d16261fd986fafb97d919584aa206ca76706fb3deccc63ab2b7f6b
- DevGlan
- www.devglan.com
字符串 text = "你好";
string key_text = "12345678901234567890123456789012345678901234567890123456789012345678901234";
https://www.devglan.com/online-tools/hmac-sha256-online-> 7558a77ff19ed6cb4777355e4bbc4772759a8130e1bb0913ba62b88411fdbaf8
测试脚本 -> 2025.02.27 22:28:43.792 Sha256TestFile (EURUSD,M5) 6d8ee9dc1d16261fd986fafb97d919584aa206ca76706fb3deccc63ab2b7f6b
我在终端上试了一下,结果与在线哈希工具相同:
2025.02.28 12:37:16.468 hashin_example_code (EURUSD,M5) 7558A77FF19ED6CB4777355E4BBC4772759A8130E1BB0913BA62B88411FDBAF8
void Hash() { // 要散列的文本 string text = "Hello"; string key_text = "1234567890123456789012345678901234567890123456789012345678901234"; HMacSha256 myhash(key_text, text); Print(myhash.hexval); }您可能需要分享您的代码。
是的,使用原始的 Sha256Algorithm.mqh 可以正常工作。我做了一些改动,也许这就是它不能工作的原因?
string CSha256Class::GetHex( void ) { string result = "" ; /* result += UintToHex(h0); result += UintToHex(h1); result += UintToHex(h2); result += UintToHex(h3); result += UintToHex(h4); result += UintToHex(h5); result += UintToHex(h6); result += UintToHex(h7); */ result += StringFormat ( "%.2x" ,h0); result += StringFormat ( "%.2x" ,h1); result += StringFormat ( "%.2x" ,h2); result += StringFormat ( "%.2x" ,h3); result += StringFormat ( "%.2x" ,h4); result += StringFormat ( "%.2x" ,h5); result += StringFormat ( "%.2x" ,h6); result += StringFormat ( "%.2x" ,h7); return (result); }
很抱歉打扰您!
- www.mql5.com
新文章 从头开始以 MQL5 实现 SHA-256 加密算法已发布:
当在交易环境中实现 SHA-256 时,性能优化变得至关重要,因为每一毫秒都会影响交易成果。自定义实现提供了若干种优化道路,而内置函数不能做到。
交易系统在其加密操作中往往展现出特定的范式。举例,订单签名典型情况下包含类似的组件,例如时间戳、品种、和数量。通过了解这些范式,我们就能针对与交易相关的数据结构专门优化 SHA-256 实现。
研究在典型交易场景中下单如何运作。每笔订单都需要多个信息片:交易对、订单类型、数量、价格、和时间戳。在标准实现中,每次都会将该数据作为全新的输入进行处理。然而,我们能够优化这一过程,即识别许多组件维持恒定,或遵循可预测的范式。
作者:Abdulkudus Okatengwu Kadir