c# - 加密 UDP 数据包

标签 c# c sockets encryption 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);
        }
    }

非常感谢

最佳答案

看看https://en.wikipedia.org/wiki/Comparison_of_cryptography_libraries获取您可以使用的加密库。

Tinc & OpenVPN 了解通过 UDP 数据包实现加密的方法。

关于c# - 加密 UDP 数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43745248/

相关文章:

c# - 删除大数据集的关闭点 C#

c - 程序在编码之前如何进行测试?

java - 在 android 中使用 php-cgi 和网络服务器

java - Client SocketInputStream.close() 导致更多的资源消耗?

java - PHP socket_write 不工作

c# - “Invoke-Sqlcmd”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

c# - 在 Windows CE 5 上安装我的程序

python在solaris中调用外部C程序

c - GetWindowText 时替换字符\uFFFD(C 代码)

javascript - SQL Server 实时推送通知到 Node.JS