在 C# 中从 TCP 套接字读取 AES 加密消息?

问题描述 投票:0回答:0

我在 C# 中使用 TCP 套接字发送和接收使用 AES 加密算法的加密消息。问题是当我使用 stream reader 收到加密消息时,它以

System.byte[]
的形式出现,我不知道如何读取它以将其传递给解密方法。

这是发送加密信息

private void backgroundWorker2_DoWork_1(object sender, DoWorkEventArgs e)
       {
           if (client.Connected)
           {
               STW.WriteLine(EncryptStringToBytes(TextToSend,key));
               this.chat_box.Invoke(new MethodInvoker(delegate ()
               {
                   chat_box.AppendText("Me : " + TextToSend + " \n");
               }
               ));
           }
           else
           {
               MessageBox.Show("Failed to send a messege");
           }
           backgroundWorker2.CancelAsync();
       } 

这是接收加密信息

 private void backgroundWorker1_DoWork_1(object sender, DoWorkEventArgs e)
        {
            while (client.Connected)
            {
                try
                {
                    recieve = STR.ReadLine();  // this message is string
                    // I need to read it as byte format to pass it to Decrytion function                
                    this.chat_box.Invoke(new MethodInvoker(delegate ()
                    {
                        chat_box.AppendText("You : " + recieve + "\n");
                    }
                    ));
                    recieve = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }

我的问题就在这里,这个消息是字符串 我需要以字节格式读取它以将其传递给解密函数

  recieve = STR.ReadLine();  // this message is string
                    // I need to read it as byte format to pass it to Decrytion function   
c# tcp aes bytestream
© www.soinside.com 2019 - 2024. All rights reserved.