Created
March 2, 2020 21:35
-
-
Save Turupawn/b5370ae6e31c29365ff6735f21f7afa3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FString ASteamAuth::base64_encode(uint8 const* bytes_to_encode, uint32 in_len) | |
{ | |
static const FString base64_chars = | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
"abcdefghijklmnopqrstuvwxyz" | |
"0123456789+/"; | |
FString ret; | |
int32 i = 0; | |
int32 j = 0; | |
uint8 char_array_3[3]; | |
uint8 char_array_4[4]; | |
while (in_len--) | |
{ | |
char_array_3[i++] = *(bytes_to_encode++); | |
if (i == 3) | |
{ | |
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; | |
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); | |
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); | |
char_array_4[3] = char_array_3[2] & 0x3f; | |
for (i = 0; (i < 4); i++) | |
{ | |
ret += base64_chars[char_array_4[i]]; | |
} | |
i = 0; | |
} | |
} | |
if (i) | |
{ | |
for (j = i; j < 3; j++) | |
char_array_3[j] = '\0'; | |
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; | |
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); | |
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); | |
for (j = 0; (j < i + 1); j++) | |
ret += base64_chars[char_array_4[j]]; | |
while ((i++ < 3)) | |
ret += '='; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment