0 votes
by (120 points)
edited

The Save() method of SshPrivateKey allows you to select a format for the private key. Why doesn't the SavePublicKey() method let you select a format?

Thanks,

John Vottero

2 Answers

0 votes
by (132k points)
edited

SshPrivateKey.SavePublicKey method only supports a single key format (Base64-encoded 'SSH2 PUBLIC KEY') at the moment. If you need to use other public key formats, please let us know which and we will happily add support or them!

by (120 points)
edited

I would like to be able to save the public key in the format that OpenSSH expects.

by (132k points)
edited

Which part of OpenSSH do you mean? If you would like to use the key to authenticate to a server, you need to save a private key, not a public key. If you need a public key to be put into the user's ~/.ssh/authorized_keys file, use SshPrivateKey.GetPublicKey() method with the code from http://www.rebex.net/support/tutorial/sftp/default.aspx#key-generation to transform it into the desired format.

0 votes
by (17.7k points)
edited

Since version 2013-R3, an overload of the SavePublicKey() method has been added:

SavePublicKey(string, SshPublicKeyFormat)    
SavePublicKey(Stream, SshPublicKeyFormat)

The following formats are supported by the SshPublicKeyFormat enum:

  • Ssh2Base64 - Base64-encoded SSH2 public key format.
  • Ssh2Raw - Raw SSH2 public key format.
...