Back to product page

Generate


Generate new pair of keys.

Type

None

Syntax

  • Basic
object.Generate KeyType, (BitCount)
The Generate(object,KeyTyple,BitCount) syntax has these parts:
objectAn expression evaluating to an object of type SSHKeyPair.
KeyTypleRequired. A SSHKeyTypes enumeration, as described in settings. Type of the key (RSA, DSA or ECDSA).
BitCountOptional. A Variant value. Number of bits in generated key.

Remarks

Generate method should be called when you need to generate new key to be used with the server. KeyType should be set either RSAkey, DSAkey or ECDSAkey. Old (if any) key loaded in memory will be destroyed, and new one will take it's place. It is advised that immediately after new key is generated, you should Save it to a file for future use.

Generate method can be a lengthy process, especially if you set large BitCount value (default BitCount is 1024). It is advised you make random mouse movements, or type on the keyboard during the keys generation, to get more random values for new keys. Possible bitcount values for generating new keys are 768, 1024 (default), 2048 and 3072.

If you with to transfer your existing keys from OpenSSH (or similar) SSH server, you can easily load such keys using Load method. In such case there is no need to generate new pair of keys.

Important thing is to keep the key private and unreadable by anyone else except yourself, and the server, of course. To help you accomplish this, storing generated keys can optionally be protected using a Password in Save method. Typical scenario to deal with generating/loading/saving keys would be something like this (sample in VB):
 
 
Private Sub Form_Load()
Dim Filename As String
Dim Password As String
   ' initialize wodSSHD
   Set wodSSHD1 = New wodSSHDCom
   ' first we need to load or generate key we will use
   ' in productional systems, generate both keys (RSA/DSA)
   ' here, just for the sample, one is enough.
   On Error Resume Next
   Filename = App.Path + "\mykey.rsa"
   ' we don't need to put password at all - but it's better in real life
   Password = "My secret password"
   ' try to load the key
   wodSSHD1.Keys.Load Filename, Password
   If Err <> 0 Then
       ' load failed - we will generate new one
       wodSSHD1.Keys.Generate RSAkey
       wodSSHD1.Keys.Save RSAkey, Filename, Password
   End If
   ' now you can start the server
End Sub
 


Code sample

  • Basic

Platforms

Windows