首页 > 解决方案 > 填充无效,即使键相同也无法删除

问题描述

我希望将消息和密钥从客户端传输到服务器。但是,我真的不明白 UDP 数据包是如何工作的。另外,有没有可能我可以通过数据包传递更多的值(超过 2 个)?

下面的代码可以获得正确的消息和密钥,并且可以解密。

this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0);
int msgLength = BitConverter.ToInt32(dataStream, 4);
int keyLength = BitConverter.ToInt32(dataStream, 8);

// Read the message field
        if (msgLength > 0)
            this.message = Encoding.UTF8.GetString(dataStream, 12, msgLength);
        else
            this.message = null;

// Read the key field
        if (keyLength > 0)
            this.secretKey = Encoding.UTF8.GetString(dataStream, 12 + msgLength, keyLength);
        else
            this.secretKey = null;

但是,当我更改 keylength 的 GetString 的值时,它会显示错误。

this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0);
int msgLength = BitConverter.ToInt32(dataStream, 4);
int keyLength = BitConverter.ToInt32(dataStream, 8);

// Read the message field
        if (msgLength > 0)
            this.message = Encoding.UTF8.GetString(dataStream, 12, msgLength);
        else
            this.message = null;

// Read the key field
        if (keyLength > 0)
            this.secretKey = Encoding.UTF8.GetString(dataStream, 12, keyLength);
        else
            this.secretKey = null;

客户端密钥 客户密钥

服务器密钥 服务器密钥

错误 错误信息

标签: c#udpaespaddingpacket

解决方案


推荐阅读