Bitmex ?
What hash are you expecting for this key/value ?
I got : C86B946CF9FBB4003B3CE68C14BB101F6366886155AF7098FBD4C0F49192270D
Bitmex ?
What hash are you expecting for this key/value ?
I got : C86B946CF9FBB4003B3CE68C14BB101F6366886155AF7098FBD4C0F49192270D
Hey Alain! Yeah, LOL. How did you know? Creepy! :D
I am expecting C86B946CF9FBB4003B3CE68C14BB101F6366886155AF7098FBD4C0F49192270D, as this is what the online generators say.
Instead I get 94dc01f15ba71f29aa6ad5facb2c056050d5f61e1ff276d3f1ec0d71fe08cebf (with AssignArray() in the second if-clause of ComputeHash()) or c60907e990745f7d91c4423713764d2724571269d3db4856d37c6302792c59a6 with InsertArray().
When you hash a string that represents a hexadecimal then there is still a difference between uppercase and lowercase so in that case it's usually necessary to first up convert the string to uppercase and then hash it.
.to_upper(data)
I found my mistakes. They were in ComputeHash(). It should be:
if (m_key.Total() < HashBlockSize) { CArrayChar newKey; newKey.Resize(HashBlockSize); for (int i=0; i<HashBlockSize; i++) newKey.Update(i,0); newKey.Insert(0,i); newKey.AssignArray(m_key); newKey.InsertArray(m_key,0); m_key = newKey; }
And:
for (int i=0; i<m_key.Total()HashBlockSize; i++) { opad.Insert((uchar)(m_key.At(i)^0x5C), i); ipad.Insert((uchar)(m_key.At(i)^0x36), i); }
I found my mistakes. They were in ComputeHash(). It should be:
And:
Friend, many thanks, is an excellent solution, congratulations, very good code :) :) :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It uses CryptEncode(CRYPT_HASH_SHA256,...) to create the hash. You can see it below! It is still very basic without error handling etc.
Usage is like this:
Unfortunately the result is different to online HMAC generators like https://www.freeformatter.com/hmac-generator.html or https://www.liavaag.org/English/SHA-Generator/HMAC/
Where is my mistake?
As you can see, I am using the build-in library CArrayChar. The methods AssignArray() and InsertArray() yield different outputs. Maybe I am using them the wrong way? Should I better use native uchar arrays everywhere instead?
Or do I have to call CryptEncode() without key somehow like in this thread (https://stackoverflow.com/a/21498946):
(No key there)
Or can I not use CryptEncode() then and I have to code the whole encryption logic myself like here? BTW: Amazing work! That would be a nightmare with my somewhat limited coding skills!
Or am I missing something fundamentally? (high probable chance 😉)