feat: wip network packet encryption

This commit is contained in:
2025-10-28 19:47:54 +03:00
parent 0691d7092c
commit 0bd2b0618d
5 changed files with 92 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
using System.Security.Cryptography;
using System.Text;
namespace Engine.Systems.Network;
public class PacketCryptor // TODO performance improvements
{
private readonly Aes aes = null!;
private readonly ICryptoTransform encrpytor = null!;
private readonly ICryptoTransform decryptor = null!;
public byte[] Encrypt(byte[] data) => encrpytor.TransformFinalBlock(data, 0, data.Length);
public byte[] Decrypt(byte[] data) => decryptor.TransformFinalBlock(data, 0, data.Length);
public PacketCryptor(string key, string initializationVector)
{
aes = Aes.Create();
aes.Key = Encoding.UTF8.GetBytes(key);
aes.IV = Encoding.UTF8.GetBytes(initializationVector);
encrpytor = aes.CreateEncryptor();
decryptor = aes.CreateDecryptor();
}
}