Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Add StringToMd5 and StringToSha1
Browse files Browse the repository at this point in the history
  • Loading branch information
trdwll committed Feb 13, 2020
1 parent e5c03e3 commit 737fb87
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 737fb87

Please sign in to comment.