-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from 0xsequence/Windows_Secure_Key
Windows secure key
- Loading branch information
Showing
16 changed files
with
197 additions
and
27 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
Plugins/SequencePlugin/Content/Core/Demonstration/BP_CustomSpectatorPawn.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions
4
Plugins/SequencePlugin/Content/Core/Pawn_Components/AC_SequencePawn_Component.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions
4
Plugins/SequencePlugin/Content/Core/Sqn_Mngrs/BP_SequenceManager.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions
4
Plugins/SequencePlugin/Content/Core/Sqn_Mngrs/BP_SqncBkndMngr.uasset
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
Plugins/SequencePlugin/Source/SequencePlugin/Private/NativeEncryptors/WindowsEncryptor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
//Copyright 2024 Horizon Blockchain Games Inc. All rights reserved. | ||
|
||
#include "NativeEncryptors/WindowsEncryptor.h" | ||
#include "Misc/Base64.h" | ||
#include "Internationalization/Regex.h" | ||
|
||
#if PLATFORM_WINDOWS | ||
#include "Windows/WindowsHWrapper.h" | ||
#include "dpapi.h" | ||
#endif | ||
|
||
FString UWindowsEncryptor::Encrypt(const FString& StringIn) | ||
{ | ||
FString Result = ""; | ||
UE_LOG(LogTemp,Display,TEXT("Preparing to encrypt on windows: %s"),*StringIn); | ||
#if PLATFORM_WINDOWS | ||
DATA_BLOB DataIn; | ||
DATA_BLOB DataOut; | ||
const FString ProcString = FBase64::Encode(StringIn); | ||
|
||
//UE_LOG(LogTemp,Display,TEXT("Decrypted PreResult: %s"),*ProcString); | ||
//UE_LOG(LogTemp,Display,TEXT("PreResult Length: %d"),ProcString.Len()); | ||
|
||
const int32 InSize = ProcString.Len(); | ||
uint8 * CharsIn = new uint8[InSize]; | ||
StringToBytes(ProcString,CharsIn,InSize); | ||
BYTE *pbDataInput = CharsIn; | ||
const DWORD cbDataInput = InSize; | ||
UE_LOG(LogTemp,Display,TEXT("InByteCount: %d"),cbDataInput); | ||
|
||
DataIn.pbData = pbDataInput; | ||
DataIn.cbData = cbDataInput; | ||
if (CryptProtectData( | ||
&DataIn, | ||
NULL, | ||
NULL, | ||
NULL, | ||
NULL, | ||
0, | ||
&DataOut)) | ||
{ | ||
BytesToHex(DataOut.pbData,DataOut.cbData,Result); | ||
LocalFree(DataOut.pbData); | ||
} | ||
else | ||
{ | ||
UE_LOG(LogTemp,Display,TEXT("Encryption Failed on windows")); | ||
} | ||
delete[] CharsIn; | ||
#endif | ||
//UE_LOG(LogTemp,Display,TEXT("Encrypted Result: %s"),*Result); | ||
return Result; | ||
} | ||
|
||
FString UWindowsEncryptor::Decrypt(const FString& StringIn) | ||
{ | ||
FString Result = ""; | ||
UE_LOG(LogTemp,Display,TEXT("Preparing to decrypt on windows: %s"),*StringIn); | ||
#if PLATFORM_WINDOWS | ||
DATA_BLOB DataIn; | ||
DATA_BLOB DataOut; | ||
|
||
const int32 InSize = StringIn.Len() / 2; | ||
uint8 * CharsIn = new uint8[InSize]; | ||
|
||
const FRegexPattern HexPattern(TEXT("^[a-fA-F0-9]+$")); | ||
FRegexMatcher HexChecker(HexPattern,StringIn); | ||
|
||
if (HexChecker.FindNext()) | ||
{ | ||
HexToBytes(StringIn,CharsIn); | ||
} | ||
else | ||
{ | ||
delete[] CharsIn; | ||
UE_LOG(LogTemp,Error,TEXT("Provided String is InValid and cannot be decoded!")); | ||
return ""; | ||
} | ||
|
||
BYTE *pbDataInput = CharsIn; | ||
const DWORD cbDataInput = InSize; | ||
DataIn.pbData = pbDataInput; | ||
DataIn.cbData = cbDataInput; | ||
LPWSTR pDescrOut = NULL; | ||
if (CryptUnprotectData( | ||
&DataIn, | ||
&pDescrOut, | ||
NULL, | ||
NULL, | ||
NULL, | ||
0, | ||
&DataOut)) | ||
{ | ||
const FString PreResult = BytesToString(DataOut.pbData,DataOut.cbData); | ||
|
||
//UE_LOG(LogTemp,Display,TEXT("Decrypted PreResult: %s"),*PreResult); | ||
//UE_LOG(LogTemp,Display,TEXT("PreResult Length: %d"),PreResult.Len()); | ||
|
||
if (FBase64::Decode(PreResult,Result)) | ||
{ | ||
UE_LOG(LogTemp,Display,TEXT("Successful B64 Decode")); | ||
} | ||
else | ||
{ | ||
UE_LOG(LogTemp,Error,TEXT("UnSuccessful B64 Decode")); | ||
} | ||
|
||
LocalFree(DataOut.pbData); | ||
LocalFree(pDescrOut); | ||
} | ||
else | ||
{ | ||
const int32 ErrorCode = GetLastError(); | ||
UE_LOG(LogTemp,Display,TEXT("Decryption Failed on windows, Error code: %d"),ErrorCode); | ||
} | ||
delete[] CharsIn; | ||
#endif | ||
//UE_LOG(LogTemp,Display,TEXT("Decrypted Result: %s"),*Result); | ||
return Result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Plugins/SequencePlugin/Source/SequencePlugin/Public/NativeEncryptors/WindowsEncryptor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//Copyright 2024 Horizon Blockchain Games Inc. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "NativeEncryptors/GenericNativeEncryptor.h" | ||
#include "WindowsEncryptor.generated.h" | ||
|
||
/** | ||
* | ||
*/ | ||
UCLASS(Blueprintable) | ||
class SEQUENCEPLUGIN_API UWindowsEncryptor : public UGenericNativeEncryptor | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
virtual FString Encrypt(const FString& StringIn) override; | ||
|
||
virtual FString Decrypt(const FString& StringIn) override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters