对于一个项目,我使用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/