feat: wip network packet encryption
This commit is contained in:
		@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user