CryptEncode(SHA1) is not returning the right SHA1 Hash

 

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);

 
   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.
 

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. 

 
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.