Sample code for 30+ languages & platforms
VB.NET

Generate an ed25519 Key and Save in PuTTY Format

See more SSH Examples

Demonstrates generating an ed25519 SSH key and saving it in PuTTY (.ppk) format, both unencrypted and encrypted. Setting the Password property and passing true to ToPuttyPrivateKey produces the encrypted form.

Note: The file paths are relative to the application's current working directory. Supply the paths to your own files.

Background: Ed25519 is the modern default for SSH keys: it offers strong security with very small keys and fast signing, and unlike RSA it has no key-size decision to get wrong. Encrypting the exported private key protects it at rest, so a stolen file is not immediately usable — the trade-off being that the passphrase must be supplied whenever the key is used, which is why unattended jobs often pair an unencrypted key with strict file permissions instead.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  This example requires the Chilkat API to have been previously unlocked.
'  See Global Unlock Sample for sample code.

'  Demonstrates generating an ed25519 SSH key and saving it in PuTTY (.ppk) format, both
'  unencrypted and encrypted.

Dim key As New Chilkat.SshKey

success = key.GenerateEd25519Key()
If (success = False) Then
    Debug.WriteLine(key.LastErrorText)
    Exit Sub
End If


'  A comment may optionally be included in the exported key.
key.Comment = "This is my new ed25519 key."

'  Export to unencrypted PuTTY format.
Dim exportEncrypted As Boolean = False
Dim exportedKey As String = key.ToPuttyPrivateKey(exportEncrypted)
If (key.LastMethodSuccess = False) Then
    Debug.WriteLine(key.LastErrorText)
    Exit Sub
End If


success = key.SaveText(exportedKey,"qa_output/privkey_putty_unencrypted.ppk")
If (success = False) Then
    Debug.WriteLine(key.LastErrorText)
    Exit Sub
End If


'  Export to encrypted PuTTY format.  The passphrase protects the private key at rest and
'  should come from a secure source rather than being hard-coded.
key.Password = "myKeyPassword"
exportEncrypted = True
exportedKey = key.ToPuttyPrivateKey(exportEncrypted)
If (key.LastMethodSuccess = False) Then
    Debug.WriteLine(key.LastErrorText)
    Exit Sub
End If


success = key.SaveText(exportedKey,"qa_output/privkey_putty_encrypted.ppk")
If (success = False) Then
    Debug.WriteLine(key.LastErrorText)
    Exit Sub
End If


Debug.WriteLine("Success!")