I have CTRL+C the example from https://docs.mql4.com/common/cryptencode and just changed encode to CRYPT_HASH_SHA256
...What am I doing wrong?
What you did wrong is to copy and paste code and changing it without understanding it ;-)
More seriously, the code you posted is NOT giving you an HMAC (see also here and here).. It gives you an hash, which doesn't need a password. So it gives the same results, whatever the key is.
2018.06.06 12:40:02.769 251371 EURUSD,M1: Initial data: size=44, string='The quick brown fox jumps over the lazy dog'
2018.06.06 12:40:02.769 251371 EURUSD,M1: Encoded data: size=32 26B54A596255364BF3B1D9B4DF2FD33D61974D1F000DF23B6F7DE4313A6C72E5 with key=craboutcha
...
2018.06.06 12:40:15.691 251371 EURUSD,M1: Initial data: size=44, string='The quick brown fox jumps over the lazy dog'
2018.06.06 12:40:15.691 251371 EURUSD,M1: Encoded data: size=32 26B54A596255364BF3B1D9B4DF2FD33D61974D1F000DF23B6F7DE4313A6C72E5 with key=ABCDEFG
Secondly the above results are different wrong because you need to take into account that a string in mql is null terminated. The length of your text string is 43, not 44.
//--- copy text to source array src[] StringToCharArray(text,src,0,StringLen(text));
What you did wrong is to copy and paste code and changing it without understanding it ;-)
More seriously, the code you posted is NOT giving you an HMAC (see also here and here).. It gives you an hash, which doesn't need a password. So it gives the same results, whatever the key is.
2018.06.06 12:40:02.769 251371 EURUSD,M1: Initial data: size=44, string='The quick brown fox jumps over the lazy dog'
2018.06.06 12:40:02.769 251371 EURUSD,M1: Encoded data: size=32 26B54A596255364BF3B1D9B4DF2FD33D61974D1F000DF23B6F7DE4313A6C72E5 with key=craboutcha
...
2018.06.06 12:40:15.691 251371 EURUSD,M1: Initial data: size=44, string='The quick brown fox jumps over the lazy dog'
2018.06.06 12:40:15.691 251371 EURUSD,M1: Encoded data: size=32 26B54A596255364BF3B1D9B4DF2FD33D61974D1F000DF23B6F7DE4313A6C72E5 with key=ABCDEFG
Secondly the above results are different wrong because you need to take into account that a string in mql is null terminated. The length of your text string is 43, not 44.
Thanks. I used the Freelance part to get dev to do my sha256/384/512 functions.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have CTRL+C the example from https://docs.mql4.com/common/cryptencode and just changed encode to CRYPT_HASH_SHA256
but the EA returns hash:
2018.06.06 11:33:23.602 !BINA_TC_000_test AUDCAD,H1: Encoded data: size=32 26B54A596255364BF3B1D9B4DF2FD33D61974D1F000DF23B6F7DE4313A6C72E5
according to this 2 websites:
https://hash.online-convert.com/sha256-generator
https://www.freeformatter.com/hmac-generator.html#ad-output
the string "The quick brown fox jumps over the lazy dog" encoded with key "ABCDEFG" with SHA256 method is: 37E35181BA93EC243CE807651A476D5304C5DED808997B01885C91CC4BEF303B
What am I doing wrong?
whole MQL4 code that you can paste as expert advisor: