//使用客户端的公共密钥加密对称密钥并发送给客。
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;