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"

SHA256 Hash FString

I simply want to SHA256 an FString to send to my server. I spent the last month creating an account server that authenticates using SHA256 strings after hearing about the flaws with SHA1. I have no problems generating SHA1 with UE4 but it seems that the 256 version is implemented differently?

Everything compiles fine but crashes during runtime

Here is the function:

 FString UHashFunctionLibrary::SHA256_ENCODE(const FString& inString) {
     uint32 size = inString.Len();
     
     TArray<uint8> sData;
     sData.AddUninitialized(size);
     StringToBytes(inString, sData.GetData(), size);
     
     FSHA256Signature retSig;
     FGenericPlatformMisc::GetSHA256Signature(sData.GetData(), size, retSig);
     return retSig.ToString();
 }

And the crash reports: Assertion failed: false [File:D:\Build\++UE4+Release- 4.18+Compile\Sync\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMisc.cpp] [Line: 899] No SHA256 Platform implementation

The problem line:

 FGenericPlatformMisc::GetSHA256Signature(sData.GetData(), size, retSig);

I haven't seen any questions asked on the forum or hub about this. I see there is a plugin or two available but I would strongly prefer not to use them. I am developing a multi-platform game and would like to use unreal's built-in hashing functions that are cross-platform compatible. I know UE4 uses SHA256 internally and there is clearly some implementation. I just don't really know what to make of that error.

Thank you so much in advance! This is a serious roadblock for me and while I could switch everything to SHA1 authentication, that would be taking a step back security-wise.

Product Version: UE 4.18
Tags:
more ▼

asked Jun 08 '18 at 12:45 PM in C++ Programming

avatar image

tehhax
196 30 28 49

avatar image tehhax Jun 09 '18 at 01:39 AM

So I took a look at the source of GetSHA256Signature() and it looks like its not implemented? The first checkf is hardcoded with false?

 bool FGenericPlatformMisc::GetSHA256Signature(const void* Data, uint32 ByteSize, FSHA256Signature& OutSignature)
 {
     checkf(false, TEXT("No SHA256 Platform implementation"));
     FMemory::Memzero(OutSignature.Signature);
     return false;
 }

Can UE4 create a SHA256 hash without a third party library?

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Use FPlatfromMisc instead of FGenericPlatformMisc. "Generic" is fall back implementation, some of them simply crashes if something is not implemented in specific platform implementation and you hit one of such examples

What UE4 platform API work is that each platform have it own of set classes, so for example Windows have prefix FWindowsPlatform* and Android for example will have FAndroidPlatform* and during compilation the specific ser for platform that compilation happens for gets typename-ed to FPlatform, so always use FPlatform. Because this is kind of a C++ hack API reference only shows Generic platform implementation which is fallback implementation that all platform implementation inherent form and if there missing function it falls back to Generic. Some platform implementations also have some extra exclusive functions, this is only case where you not use FPlatfrom and reference platform implementation directly

more ▼

answered Jun 09 '18 at 02:38 AM

avatar image

Shadowriver
33.9k 916 164 1093

avatar image tehhax Jun 09 '18 at 06:51 AM

Thanks for the reply! Unfortunately changing "FGenericPlatformMisc" to "FPlatformMisc" still produces the same error. It seems to be calling the generic one anyways :(

 Assertion failed: false [File:D:\Build\++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMisc.cpp] [Line: 899] No SHA256 Platform implementation

avatar image Shadowriver Jun 23 '18 at 10:26 PM

You right there no implmentation on any platfrom and this function in engine is only used by HTTP module. I can only find MD5 and SHA1 implmentations in engine:

https://github.com/EpicGames/UnrealEngine/blob/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Source/Runtime/Core/Public/Misc/SecureHash.h

Hmmm you could try calling OpenSSL direcly for SHA256 hash, OpenSSL is included in UE4, you just need to ThirdParty depency in your module build script, here example:

https://github.com/EpicGames/UnrealEngine/blob/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Plugins/Developer/PerforceSourceControl/Source/PerforceSourceControl/PerforceSourceControl.Build.cs

(comments are locked)
10|2000 characters needed characters left

Got it working.. prehaps its not best solution but its working for me.

I using the sha256.h and sha256.cpp file from zedwood function. found here http://www.zedwood.com/article/cpp-sha256-function

Jah need to insert the #define _CRT_SECURE_NO_WARNINGS in the sha256.cpp

Because the function expects std.string and not fstring .. jah need to convert them like this FString hash_user_name = *FString(sha256(TCHAR_TO_UTF8(*User_Name)).c_str());

Then jah can get the code working and jah got a nice sha256 hash signature.

more ▼

answered Jan 18 '19 at 06:50 PM

avatar image

shadow_tj
1

(comments are locked)
10|2000 characters needed characters left
Your answer
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