As there are many gotchas when it comes to encodings and I could not find any code that used the internal SHA1 implementation I would love if someone with some more experience could verify that I’m not being stupid as I’m not a cpp programmer at all.
Also, if this is working as intended then I guess this place is as good as any to share that information.
h file
static FString SHA1(const FString & Data);
cpp file
#include "SecureHash.h"
#include <string>
FString UVHServerCommunication::SHA1(const FString & Data)
{
//Make sure we are using UTF-8 as the browser
//and server will be using UTF-8
std::string stdstring(TCHAR_TO_UTF8(*Data));
FSHA1 HashState;
HashState.Update((uint8*)stdstring.c_str(), stdstring.size());
HashState.Final();
uint8 Hash[FSHA1::DigestSize];
HashState.GetHash(Hash);
return BytesToHex(Hash, FSHA1::DigestSize);
}
The thing I am worried about is stdstring(TCHAR_TO_UTF8(*Data)), is there some strange chars that will break this? I have tried stuff with åäö and some other signs and it seems to work but I don’t want to figure out after a while that there is chars that gives the wrong hash.