In SecureFTPConnection, the algorithms that the client presents to the server for negotiation can be specified if required. The server will have its own set of preferred algorithms configured, and the protocol chooses one of the algorithms supported by both client and server, preferencing the client order.
Note that SecureFTPConnection is already configured with all its available algorithms. The main reason for modifying them is to restrict the algorithms being used.
Public key algorithms
In SSH, public key algorithms are used for authentication. The available client public key algorithms are listed here. If, for example, Ed25519 is set, the server will present an Ed25519 public key to the client (if the server supports Ed25519 keys). The code below illustrates how to set Ed25519 only:
ftpConnection.PreferredHostKeyAlgorithms = SSHPublicKeyAlgorithm.Ed25519;
The default is all public key algorithms enabled.
Cipher algorithms
The cipher algorithms are the symmetric algorithms used to perform the encryption of the SFTP data and commands. The available client cipher algorithms are listed here. The list of algorithms presented to the server on connection has the strongest algorithms listed first. The code below illustrates how to set AES-GCM-128 as the cipher algorithm:
ftpConnection.PreferredCipherAlgorithms = SSHCipherAlgorithm.AES_GCM_128;
The default is all algorithms enabled.
The enum is used as a bitwise flag, so members of SSHCipherAlgorithm can be OR'd together to indicate more than one algorithm, as shown below:
ftpConnection.PreferredCipherAlgorithms = SSHCipherAlgorithm.AES_CTR_256 | SSHCipherAlgorithm.AES_GCM_256;
To reset to all algorithms, use the All value:
ftpConnection.PreferredCipherAlgorithms = SSHCipherAlgorithm.All;
MAC algorithms
The MAC algorithms are the algorithms used to protect the integrity and authenticity of each encrypted SSH packet. The available client MAC algorithms are listed here. The list of algorithms presented to the server on connection has the strongest algorithms listed first. The code below illustrates how to set HMAC-SHA2-256-ETM as the cipher algorithm:
ftpConnection.PreferredMACAlgorithms = SSHMACAlgorithm.HMAC_SHA2_256_ETM;
The default is all algorithms enabled.
The enum is used as a bitwise flag, so members of SSHMACAlgorithm can be OR'd together to indicate more than one algorithm, as shown below:
ftpConnection.PreferredMACAlgorithms = SSHMACAlgorithm.HMAC-SHA2-256-ETM | SSHMACAlgorithm.HMAC-SHA2-256;
To reset to all algorithms, use the All value:
ftpConnection.PreferredMACAlgorithms = SSHMACAlgorithm.All;
Key exchange algorithms
The MAC algorithms are used to establish shared secret key material between client and server. The available client key exchange algorithms are listed here. The list of algorithms presented to the server on connection is ordered with the strongest algorithms listed first. The code below illustrates how to set HMAC-SHA2-256-ETM as the cipher algorithm:
ftpConnection.PreferredKeyExchangeMethods = SSHKeyExchangeMethod.HMAC_SHA2_256_ETM;
The default is all algorithms enabled.
The enum is used as a bitwise flag, so members of SSHKeyExchangeMethod can be OR'd together to indicate more than one algorithm, as shown below:
ftpConnection.PreferredKeyExchangeMethods = SSHKeyExchangeMethod.HMAC-SHA2-256-ETM | SSHKeyExchangeMethod.HMAC-SHA2-256;
To reset to all algorithms, use the All value:
ftpConnection.PreferredKeyExchangeMethods = SSHKeyExchangeMethod.All;