CryptEncode without using a key ?

 

Hello, i got a string to encode into SHA-256. For this, i'm using the CryptEncode function with my string converted to char array.

I do not need to encrypt this array with any key, as the key is already hand crafted into this string (this is something i cant change).

Example :

StringToCharArray(_tohash,src);
StringToCharArray(_saltkey,key);

where :

string _saltkey = "1234";
string _tohash = "my message to be encrypted"+_mysaltkey;

I dont understand why my hashed result returned by :

CryptEncode(CRYPT_HASH_SHA256,src,key,_hashed);

is different from using an online hash online utility like this :

I think it may have something to deal with the "key" in CryptEncode function, so is there a way to use it without any key while not altering the result, which has to be the same as an online PHP generator.

I would appreciate any help, as i am really stuck right now :'( Thanks !



 
StringToCharArray(_tohash,src);

should be

   StringToCharArray(_tohash,src,0,StringLen(_tohash));

and you have an error :

string _saltkey = "1234";
string _tohash = "my message to be encrypted"+_mysaltkey;
 
Alain Verleyen:

should be

and you have an error :

Thanks a lot Alain. It does now work perfectly !
Reason: