public IKeyExchange CreateKeyExchange(IDictionary<string, Type> clientAlgorithms, string[] serverAlgorithms)
{
if (clientAlgorithms == null)
throw new ArgumentNullException("clientAlgorithms");
if (serverAlgorithms == null)
throw new ArgumentNullException("serverAlgorithms");
// find an algorithm that is supported by both client and server
var keyExchangeAlgorithmType = (from c in clientAlgorithms
from s in serverAlgorithms
where s == c.Key
select c.Value).FirstOrDefault();
if (keyExchangeAlgorithmType == null)
{
throw new SshConnectionException("Failed to negotiate key exchange algorithm.", DisconnectReason.KeyExchangeFailed);
}
return keyExchangeAlgorithmType.CreateInstance<IKeyExchange>();
}
}