x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UTF-8 based SHA1 from FString.

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. :P

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.

Product Version: UE 4.8
Tags:
more ▼

asked Jul 31 '15 at 12:25 AM in C++ Programming

avatar image

PhroZenOne
154 7 16 22

avatar image Omberone Nov 13 '15 at 10:07 AM

I'm pretty sure something breaks if you do

 FString str("åäö");
 auto _utf8 = TCHAR_TO_UTF8(str);
 str = UTF8_TO_TCHAR(_utf8);

I have no idea why though.

avatar image PhroZenOne Nov 16 '15 at 07:11 AM

Strange, I think I tried that and verified it worked. I'll have a look again when I get home from work and report back.

avatar image Omberone Nov 17 '15 at 09:46 AM

Alright, here's the gist; if the string is longer than 128U characters it will break. Also, we did mess up with the conversion since we stored the converted UTF8 string with the size of char times the length of the string, which isn't correct after conversion.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question