public void Process(byte[] buffer, Connection connection) { var msg = new ByteBuffer(buffer); int length; length = msg.ReadInt32(); var key = msg.ReadBytes(length); length = msg.ReadInt32(); var iv = msg.ReadBytes(length); var rsa = connection.RSAKey.GetKey(); var _key = RSACryptography.RSADecrypt(key, rsa.GetPrivateKey(), false); var _iv = RSACryptography.RSADecrypt(iv, rsa.GetPrivateKey(), false); connection.AesKey.SetClientKey(_key); connection.AesKey.SetClientIv(_iv); // Encria e envia de volta para o cliente. _key = connection.AesKey.GetKey(); _iv = connection.AesKey.GetIv(); key = RSACryptography.RSAEncrypt(_key, rsa.GetClientPublicKey(), false); iv = RSACryptography.RSAEncrypt(_iv, rsa.GetClientPublicKey(), false); var aes = new SpAESKey(key, iv); aes.Send(connection, false); }
public void Process(byte[] buffer, Connection connection) { var msg = new ByteBuffer(buffer); int length; length = msg.ReadInt32(); var key = msg.ReadBytes(length); length = msg.ReadInt32(); var iv = msg.ReadBytes(length); var rsa = connection.RSAKey; var keys = rsa.GetKey(); var _key = RSACryptography.RSADecrypt(key, keys.GetPrivateKey(), false); var _iv = RSACryptography.RSADecrypt(iv, keys.GetPrivateKey(), false); connection.AesKey.SetClientKey(_key); connection.AesKey.SetClientIv(_iv); Global.Socket.HandShake = true; }