The SSH key format is rather complex; if you want to implement it yourself, this, this and this answer might be a good start.
However, someone else actually already did the work and created a NuGet package for generating SSH keys: SshKeyGenerator. Right now the package is offered for both .NET Framework and .NET Standard. The source code is available on GitHub.
Example code:
static void Main(string[] args)
{
int keyBits = 2048;
string keyComment = "mykey";
var keygen = new SshKeyGenerator.SshKeyGenerator(keyBits);
Console.WriteLine(keygen.ToPrivateKey());
Console.WriteLine(keygen.ToRfcPublicKey(keyComment));
}
generates (shortened for readability)
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA7ejxsqTKLMLht6HVC57l59mMzQNIVdeMaPzxM14VYjkyU1rg
...
L4NAI1BCgGpSC+iY3QuVwK8GVphVSzNrOQj97Uuhx0WYsEdPzJvjQw==
-----END RSA PRIVATE KEY-----
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD...nFX7Rhou4OdkDGA1 mykey
Note that the package currently does not support setting a private key passphrase.