Back to product page
Generate method
Generate new pair of keys.
Type
NoneSyntax
- Basic
object.Generate KeyType, [BitCount]
The Generate(object,KeyType,BitCount) syntax has these parts:
The Generate(object,KeyType,BitCount) syntax has these parts:
object | An expression evaluating to an object of type Keys. |
KeyType | Required. A SSHKeyTypes enumeration, as described in settings. Type of the key. |
BitCount | Optional. A Variant value. Specifies total number of bits in generated key (defaults to 1024). |
Remarks
The settings for KeyType are:Constant | Value | Description |
---|---|---|
RSAkey | 0 | Uses RSA algorithm to create keys. |
DSAkey | 1 | Uses DSA algorithm to create keys. |
ECDSAkey | 2 | Uses ECDSA algorithm to create keys. |
Generate method should be called when you need to generate new key to be used with the server. KeyType should be set to 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 (for RSA and DSA), and 256, 384 and 521 for ECDSA key.
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. To help you accomplish this, storing generated keys can optionally be protected using a Password in Save method.
Code sample
- Basic
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 Keys component
Dim Keys As New WODSSHKeyLib.Keys
' first we need to load or generate key we will use
' 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
Keys.Load Filename, Password
If Err <> 0 Then
' load failed - we will generate new one
Keys.Generate RSAkey
Keys.Save RSAkey, Filename, Password
End If
' now you can continue with your code
End Sub
Private Sub Form_Load()
Dim Filename As String
Dim Password As String
' initialize Keys component
Dim Keys As New WODSSHKeyLib.Keys
' first we need to load or generate key we will use
' 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
Keys.Load Filename, Password
If Err <> 0 Then
' load failed - we will generate new one
Keys.Generate RSAkey
Keys.Save RSAkey, Filename, Password
End If
' now you can continue with your code
End Sub