Save public key in OpenSSH format

0 votes
asked Jul 17, 2012 by JohnVottero (120 points)
edited Dec 9, 2013

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?


John Vottero

2 Answers

0 votes
answered Jul 18, 2012 by Lukas Pokorny (126,910 points)
edited Jul 20, 2012

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!

commented Jul 18, 2012 by JohnVottero (120 points)
edited Jul 18, 2012

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

commented Jul 20, 2012 by Lukas Pokorny (126,910 points)
edited Jul 20, 2012

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 to transform it into the desired format.

0 votes
answered Dec 9, 2013 by Jan Sotola (17,670 points)
edited Dec 9, 2013

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.