Method Generate
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
Generate(SshKeyType, string?, int)
Generates a new key pair, as ssh-keygen -t does. Write it with SaveAsync(string, string?, CancellationToken) or ToOpenSshPrivateKey(string?, int),
and give the server ToAuthorizedKeysLine().
public static SshPrivateKey Generate(SshKeyType type, string? comment = null, int rsaBits = 3072)
Parameters
typeSshKeyTypeThe key type. Ed25519 is the usual choice; ECDSA or RSA where FIPS-approved algorithms are required.
commentstringThe comment stored with the key, often
user@host.rsaBitsintThe RSA key size: 3072 by default (as ssh-keygen), from 2048 to 16384. Ignored for other types.
Returns
Exceptions
- ArgumentOutOfRangeException
rsaBitsis not a supported RSA key size.