From 737fb874913cdade076579cdd2a7ea5b1ce40689 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Thu, 13 Feb 2020 05:08:31 -0500 Subject: [PATCH] Add StringToMd5 and StringToSha1 --- Source/VaRest/Private/VaRestLibrary.cpp | 21 +++++++++++++++++++++ Source/VaRest/Public/VaRestLibrary.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index d241c00f..e342e447 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -41,3 +41,24 @@ bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray& 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; +} diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 0ef6323f..40da5bc5 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -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& 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); };