加密UDP数据包



对于一个项目,我使用UDP数据包发送和接收数据。但是现在我的主管要我加密这些数据包,以便在捕获例如Wireshark时无法使用它们。我想知道是否有一种简单的方法可以使用C或C#中的内置功能来执行此操作。否则,如何制作自己的加密功能?

下面的代码是我在C#中发送数据并在C程序中接收数据的方式。

        var client = new UdpClient();
        IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 21); // endpoint where server is listening
        client.Connect(ep);
        string text = textBox1.Text;
        char[] arr= text.ToCharArray(0,text.Length);
        // send data
        var arr2 = new byte[100];
        arr2[0] = 0x32;
        arr2[1] = 0x40;
        arr2[2] = (byte)(text.Length);
        if(text.Length==0)
        {
            arr2[2] = 0x00;
            arr2[3] = 0x00;
            arr2[4] = 0x01;
            client.Send(arr2, text.Length + 4);
        }
        else
        {
            for (int i = 3; i < text.Length + 3; i++)
            {
                arr2[i] = (byte)arr[i - 3];
            }
            client.Send(arr2, text.Length + 3);
        }
    }

thanx很多

请查看https://en.wikipedia.org/wiki/comparison_of_cryptography_libraries for您可以使用的加密库。

>

看Tinc&amp;OpenVPN使用UDP数据包实现加密的方法。

最新更新