加密UDP数据包
问题描述:
对于一个项目,我使用UDP数据包来发送和接收数据。 但现在我的主管要我加密数据包,以便在用Wireshark捕获数据包时不能使用它们。我想知道是否有一种简单的方法来使用C或C#中的内置函数来完成此操作。否则,我该如何创建自己的加密功能?加密UDP数据包
以下代码是我如何使用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#加密”。有成千上万的结果。 – Gusman