Download MetaTrader 5

CryptEncode(SHA1) is not returning the right SHA1 Hash

To add comments, please log in or register
Wisam Naji
120
Wisam Naji  

Hello friends,

In my code I need to encode a key into SHA1 hash but as I tried so many times the generated hash is not what it should be for the same src[].


Here is my code:

From the code below the generated hash is:              "386c7d21720cc304f8d97435de3080fbbdf3c7b1"

While it should be :                                                  "f58dd8d6effd71050ee5979960ca18c28eb3fd54"


Am I Missing Something??


string keys ="", srcs="06DA43DD91584F82BF2EB9D7F5BAD7";
uchar src[],dst[],key[];
StringToCharArray(keys,key);
StringToCharArray(srcs,src);
int k = CryptEncode(CRYPT_HASH_SHA1,src,key, dst);
hash = "";
for(int i=0;i<k;i++)
  {
   hash +=StringFormat("%.2x",dst[i]);
  }
Print(hash);

Alain Verleyen
Moderator
33621
Alain Verleyen  
   string srcs="06DA43DD91584F82BF2EB9D7F5BAD7";
   uchar src[],dst[],key[],temp[];
   StringToCharArray(srcs,src);
   ArrayResize(src,ArraySize(src)-1);
   int k=CryptEncode(CRYPT_HASH_SHA1,src,key,dst);
   string hash="";
   for(int i=0;i<k;i++)
     {
      hash+=StringFormat("%.2x",dst[i]);
     }
   Print(hash);
mql5 string are null terminated.
Pedro Miranda
1196
Pedro Miranda  

Hello,

I am curious about what the CryptEncode function does.

Does it concatenate the Source String with the Key before hashing?
If it does what is the order of the concatenation? The source or the key will come first?

 

It is simply not documented. 

Alain Verleyen
Moderator
33621
Alain Verleyen  
Pedro:

Hello,

I am curious about what the CryptEncode function does.

Does it concatenate the Source String with the Key before hashing?
If it does what is the order of the concatenation? The source or the key will come first?

 

It is simply not documented. 

What is not documented ? All CryptEncode methods are well know and documented algorithms.

To add comments, please log in or register