mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-12 21:04:41 +01:00
Init enter game
This commit is contained in:
35
Common/Util/Crpyto/DispatchEncryption.cs
Normal file
35
Common/Util/Crpyto/DispatchEncryption.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace KianaBH.Util.Crypto;
|
||||
|
||||
public static class DispatchEncryption
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
};
|
||||
|
||||
public static string? EncryptDispatchContent(string version, object? data)
|
||||
{
|
||||
if (!ConfigManager.Hotfix.AesKeys.TryGetValue(version, out var aesKey))
|
||||
return null;
|
||||
|
||||
var serializedData = JsonSerializer.Serialize(data, JsonSerializerOptions);
|
||||
var keyBytes = aesKey.Split(' ')
|
||||
.Select(b => Convert.ToByte(b, 16))
|
||||
.ToArray();
|
||||
|
||||
using var aes = Aes.Create();
|
||||
aes.Mode = CipherMode.ECB;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
aes.Key = keyBytes;
|
||||
|
||||
var encryptor = aes.CreateEncryptor();
|
||||
var dataBytes = Encoding.UTF8.GetBytes(serializedData);
|
||||
var encryptedBytes = encryptor.TransformFinalBlock(dataBytes, 0, dataBytes.Length);
|
||||
|
||||
return Convert.ToBase64String(encryptedBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user