Skip to content

Commit

Permalink
Merge pull request #268 from trdwll/hashing
Browse files Browse the repository at this point in the history
Add StringToMd5 and StringToSha1
  • Loading branch information
ufna committed Feb 13, 2020
2 parents e5c03e3 + 737fb87 commit 6371b53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/VaRest/Private/VaRestLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray<uint8>& Dest
{
return FBase64::Decode(Source, Dest);
}

FString UVaRestLibrary::StringToMd5(const FString& StringToHash)
{
return FMD5::HashAnsiString(*StringToHash);
}

FString UVaRestLibrary::StringToSha1(const FString& StringToHash)
{
FSHA1 Sha1Gen;

Sha1Gen.Update((unsigned char*)TCHAR_TO_ANSI(*StringToHash), FCString::Strlen(*StringToHash));
Sha1Gen.Final();

FString Sha1String;
for (int32 i = 0; i < 20; i++)
{
Sha1String += FString::Printf(TEXT("%02x"), Sha1Gen.m_digest[i]);
}

return Sha1String;
}
6 changes: 6 additions & 0 deletions Source/VaRest/Public/VaRestLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode Data"))
static bool Base64DecodeData(const FString& Source, TArray<uint8>& Dest);

UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5"))
static FString StringToMd5(const FString& StringToHash);

UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to SHA1"))
static FString StringToSha1(const FString& StringToHash);
};

0 comments on commit 6371b53

Please sign in to comment.