日期:2010-05-02  浏览次数:20408 次

//使用客户端的公共密钥加密对称密钥并发送给客。
encryptAndSendSymmetricKey(client, rsa, symm);

//使用对称密钥加密信息并发送
encryptAndSendSecretMessage(client, symm, msg);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
finally
{
try
{
client.Close();
listener.Stop();
}
catch
{
//错误
}
Console.WriteLine("Server exiting...");
}
}

private static RSAParameters getClientPublicKey(TcpClient client)
{
// 从字节流获取串行化的公共密钥,通过串并转换写入类的实例
byte[] buffer = new byte[RSA_KEY_SIZE_BYTES];
NetworkStream ns = client.GetStream();
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
RSAParameters result;

int len = 0;
int totalLen = 0;