27 lines
805 B
C#
27 lines
805 B
C#
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();
|
|
}
|
|
}
|