mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
* Fix AutoFishing crash * Fix all warnings * Remove DotNetZip. * Fix the usage of HttpClient.
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace MinecraftClient.Protocol
|
|
{
|
|
// Thanks to https://stackoverflow.com/questions/60404612/parse-jwt-token-to-get-the-payload-content-only-without-external-library-in-c-sh
|
|
public static class JwtPayloadDecode
|
|
{
|
|
public static string GetPayload(string token)
|
|
{
|
|
var content = token.Split('.')[1];
|
|
var jsonPayload = Encoding.UTF8.GetString(Decode(content));
|
|
return jsonPayload;
|
|
}
|
|
|
|
private static byte[] Decode(string input)
|
|
{
|
|
var output = input;
|
|
output = output.Replace('-', '+'); // 62nd char of encoding
|
|
output = output.Replace('_', '/'); // 63rd char of encoding
|
|
switch (output.Length % 4) // Pad with trailing '='s
|
|
{
|
|
case 0: break; // No pad chars in this case
|
|
case 2: output += "=="; break; // Two pad chars
|
|
case 3: output += "="; break; // One pad char
|
|
default: throw new System.ArgumentOutOfRangeException(nameof(input), "Illegal base64url string!");
|
|
}
|
|
var converted = Convert.FromBase64String(output); // Standard base64 decoder
|
|
return converted;
|
|
}
|
|
}
|
|
}
|