Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 简单聊天客户端服务器加密_C#_Encryption_Client_Client Server_Aes - Fatal编程技术网

C# 简单聊天客户端服务器加密

C# 简单聊天客户端服务器加密,c#,encryption,client,client-server,aes,C#,Encryption,Client,Client Server,Aes,我想用AES-256bit制作一个聊天客户端服务器,非常简单,但同时也非常安全。我也这么认为,当然,如果我错了,请告诉我。 各种客户端在“安全”文本框中输入密码(在任何地方都必须相同),在发送功能(客户端程序)中,客户端使用密码加密我放在另一个普通文本框中的消息,并将其发送到服务器;接收函数总是使用相同的密钥进行解密。服务器不应在加密级别执行任何操作。 我试过了,但我不知道它是否因为代码级别的原因而不起作用。 下面是我如何修改客户端上的发送和接收函数:send函数 // send the mes

我想用AES-256bit制作一个聊天客户端服务器,非常简单,但同时也非常安全。我也这么认为,当然,如果我错了,请告诉我。 各种客户端在“安全”文本框中输入密码(在任何地方都必须相同),在发送功能(客户端程序)中,客户端使用密码加密我放在另一个普通文本框中的消息,并将其发送到服务器;接收函数总是使用相同的密钥进行解密。服务器不应在加密级别执行任何操作。 我试过了,但我不知道它是否因为代码级别的原因而不起作用。 下面是我如何修改客户端上的发送和接收函数:send函数

// send the message to the server
private void SendMessage()
{
    if (txtMessage.Lines.Length >= 1)
    {
        byte[] passwordBytes = GetPasswordBytes();
        encrypted_message = AES.Encrypt(txtMessage.Text, passwordBytes);
        swSender.WriteLine(encrypted_message);
        swSender.Flush();
        txtMessage.Lines = null;
    }
    txtMessage.Text = "";
}
接收功能:

private void ReceiveMessages()
{
    // Receive the response from the server
    srReceiver = new StreamReader(tcpServer.GetStream());
    // If the first character of the response is 1, connection was successful
    string ConResponse = srReceiver.ReadLine();
    // If the first character is a 1, connection was successful
    if (ConResponse[0] == '1')
    {
        // Update the form to tell it we are now connected
        this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { "Connessione avvenuta con successo!" });
    }
    else // If the first character is not a 1 (probably a 0), the connection was unsuccessful
    {
        string Reason = "Non connesso: ";
        // Extract the reason out of the response message. The reason starts at the 3rd character
        Reason += ConResponse.Substring(2, ConResponse.Length - 2);
        // Update the form with the reason why we couldn't connect
        this.Invoke(new CloseConnectionCallback(this.CloseConnection), new object[] { Reason });
        // Exit the method
        return;
    }
    // While we are successfully connected, read incoming lines from the server
    while (Connected == true)
    {
            try
            {
                // Show the messages decrypted in the log TextBox
                this.Invoke(new UpdateLogCallback(this.MessageUpdateLog), new object[] { srReceiver.ReadLine() });

            }
            catch
            {
                try
                {
                this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { srReceiver.ReadLine() });
                }
                catch { }
            }
    }
}

// This method is called from a different thread in order to update the log TextBox
private void UpdateLog(string strMessage)
{
    txtLog.AppendText(strMessage + "\r\n");
}

//Decrypt the messages incoming from the other client
private void MessageUpdateLog(string strMessage_de)
{
    byte[] passwordBytes = GetPasswordBytes();
    strMessage_de = AES.Decrypt(strMessage_de, passwordBytes);
    // Append text also scrolls the TextBox to the bottom each time
    txtLog.AppendText(strMessage_de + "\r\n");
}

为了不让这项工作变得困难,我想到了通过语音交换加密密码(密钥),因为这将是一个供个人使用的聊天室。

这里有问题吗?是的,因为这不起作用。程序在逻辑层或代码层不工作?这里有问题吗?是的,因为这不工作。程序不在逻辑层或代码层工作?