1

Can anyone point me towards a file format for OpenSSH keys? Sample code would be fantastic but even a pointer towards the relevant RFC would be a big help.

As background, I have a C# program which needs to generate a ssh key at runtime. The program will be run on Windows, Linux and Mac so I'd prefer to generate the public/private key pair in C# rather than calling out to platform-specific tools/libraries. I can generate the components of a key using System.Security.Cryptography.RSACryptoServiceProvider but suspect I'm not then writing these out correctly.

Thanks.

simonc
  • 41,632
  • 12
  • 85
  • 103
  • as a general principle, you SHOULD be using a trusted library to generate keys. If you implement the crypto functions yourself, chances are 1) they will be buggy and 2) no one will or should trust them without a thorough scrutiny of your source code. – Ahmed Masud Feb 06 '12 at 17:23
  • @AhmedMasud can you elaborate on your concerns please? I thought I was using a trusted library to generate the key by using RSACryptoServiceProvider as provided by MS/mono. My problem is with how to serialise the key to file in a format which'll be understood by ssh clients (specifically the SSH.NET library). – simonc Feb 06 '12 at 23:00

1 Answers1

1

The Secure Shell (SSH) Public Key File Format RFC Is that what you were looking for ?

Also worth a look (unverified by me) is if Putty uses the official libs or own implementations http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Putty is an open source ssh client that can generate keys if I recall right. Maybe you'll find code there that's easier to take out.
Otherwise maybe just dig into ssh-keygen sources

I've been working on such code in the past, it was a real headache ;)

Community
  • 1
  • 1
John
  • 7,507
  • 3
  • 52
  • 52
  • 1
    Thanks but its the private key format I'm looking for and I think OpenSSH keys are slightly different to these too. +1 for suggesting inspecting the puttygen source though – simonc Feb 06 '12 at 23:02