-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUE5Bridge.cpp
More file actions
80 lines (65 loc) · 2.21 KB
/
Copy pathUE5Bridge.cpp
File metadata and controls
80 lines (65 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "UE5Bridge.h"
namespace EncryptionKeys
{
static const int TIMESTAMP_ADDER = 123456789;
static const auto MD5_HASH_KEY = "a25ea98b37d4efb661f2cf679e1a9bfd165060a7"; // md5 hash of "ue5-laravel-bridge"
}
struct AnotherFenceToGetOverEncryption
{
static FString Encrypt(const FString& InputString, const FString& Key)
{
TArray<uint8> EncryptedData;
int32 KeyIndex = 0;
for (int32 i = 0; i < InputString.Len(); ++i)
{
uint8 EncryptedByte = InputString[i] ^ Key[KeyIndex];
EncryptedData.Add(EncryptedByte);
KeyIndex = (KeyIndex + 1) % Key.Len();
}
return FBase64::Encode(EncryptedData.GetData(), EncryptedData.Num());
}
static FString Decrypt(const FString& EncodedString, const FString& Key)
{
TArray<uint8> DecodedData;
FBase64::Decode(EncodedString, DecodedData);
FString DecryptedString;
int32 KeyIndex = 0;
for (int32 i = 0; i < DecodedData.Num(); ++i)
{
uint8 const DecryptedByte = DecodedData[i] ^ Key[KeyIndex];
DecryptedString.AppendChar(DecryptedByte);
KeyIndex = (KeyIndex + 1) % Key.Len();
}
return DecryptedString;
}
};
FString UUE5Bridge::GetCurrentTime() {
FDateTime const Time = FDateTime::UtcNow();
FString CurrentTime = Time.ToString();
return CurrentTime;
}
FString UUE5Bridge::GenerateDynamicTokenFromTime(FString IncomingTime) {
FDateTime ParsedDateTime;
if (FDateTime::Parse(IncomingTime, ParsedDateTime))
{
FDateTime const CurrentTime = ParsedDateTime;
FDateTime const DynamicTime = CurrentTime + FTimespan::FromSeconds(EncryptionKeys::TIMESTAMP_ADDER);
FString DynamicToken = DynamicTime.ToString();
return DynamicToken;
}
// Error ?
return "";
}
FString UUE5Bridge::HashToken(const FString& DynamicToken) {
FString EncryptedString = AnotherFenceToGetOverEncryption::Encrypt(DynamicToken, EncryptionKeys::MD5_HASH_KEY);
return EncryptedString;
}
TMap<FString, FString> UUE5Bridge::GetHashedToken(const TMap<FString, FString>& Params) {
TMap<FString, FString> newParams = Params;
FString const currentTime = GetCurrentTime();
newParams.Add("timestamp", currentTime);
FString const timeToken = GenerateDynamicTokenFromTime(currentTime);
FString const csrfToken = HashToken(timeToken);
newParams.Add("token", csrfToken);
return newParams;
}